Deploy Token on SUI 🚀 (Move 2024 edition) and Tips and Trick.
Published: 2024-05-13 06:29:16

Move the 2024 edition onwards

Let’s start

Install SUI

brew

```brew install sui```
Cargo 🦀

```cargo install --locked --git https://github.com/MystenLabs/sui.git --branch testnet sui```

Run the following command to create your Sui account:

Set Up Sui on Devnet

Configure the Sui CLI to use the DevNet environment. This typically involves setting the network configuration to point to DevNet endpoints.

```sui config set --network devnet```

```sui client new-address ed25519```
You can check your active address via sui client active-address and switch to a new address via sui client switch --address [ADDRESS]

Obtain Sui Tokens from the Faucet
sui client faucet --address <YOUR_SUI_ADDRESS>
You can check your balance via sui client gas which will output something like this:

Note: You’ll need to replace recipient with the address you generated above.

Verify Your Sui Address
```sui keytool list```

Create a New Move Package
sui move new my_first_package
Check Active Address
Make sure that your newly created Sui address is set as the active address in your Sui CLI configuration.

sui client active-address

```
module your_namespace::YourToken {
    use std::option;
    use sui::coin;
    use sui::transfer;
    use sui::tx_context::{Self, TxContext};

   // Name matches the module name, but in UPPERCASE
   // Internal struct declarations are not yet supported annotations are required on struct declarations from the Move 2024 edition onwards.
    public struct YourToken has key, store {}

    public fun initialize(ctx: &mut TxContext) {
        let (treasury, _metadata) = coin::create_currency<YourToken>(1000000, 6, b"YT", b"YourToken", b"Your token description", option::some(ctx.sender));
        transfer::public_freeze_object(metadata);
        // deploy and mint_and_transfer token
        coin::mint_and_transfer(&mut treasury, 1000000000000000000, tx_context::sender(ctx), ctx);
        transfer::public_transfer(treasury, tx_context::sender(ctx));
    }
    
    public entry fun mint(treasury: &mut coin::TreasuryCap<YourToken>, amount: u64, recipient: address) {
        coin::mint(treasury, amount, recipient);
    }
    
    public entry fun burn(treasury: &mut coin::TreasuryCap<SUPRA>, coin: coin::Coin<SUPRA>) {
        coin::burn(treasury, coin);
    }
}
```

For your token LOGO 😎

```
use sui::url
 const IconUrl: vector<u8> = b"your_ipfs_Url";
```
you can update the logo file 
here: {% embed https://nft.storage/ %} or {% embed https://www.pinata.cloud/ %}

Update init token

```
    fun init(witness: YourToken, ctx: &mut TxContext) {
        let ascii_url = std::ascii::string(IconUrl);
        let icon_url = url::new_unsafe(ascii_url);
    // Declare 'treasury' as mutable
        let (mut treasury, metadata) = coin::create_currency(witness, 9, b"symbol_YourToken", b"YourToken", b"YourToken info", option::some(icon_url), ctx);
```

Check your move version or migrate new version

```sui move migrate```

UPDATING GIT DEPENDENCY 
https://github.com/MystenLabs/sui.git
Package toml does not specify an edition. As of 2024, Move requires all packages to define a language edition.

Please select one of the following editions:

1) 2024.beta
2) legacy

Selection (default=1): 1


Would you like the Move compiler to migrate your code to Move 2024? (Y/n) y

Generated changes . . .
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING firoll

No migration is required. Enjoy!
Recorded edition in 'Move.toml'
Let’s Deploy and Test!
sui client publish --gas-budget 10000000
or

sui client publish --gas-budget 100000000 --skip-dependency-verification

Interaction
Mint Token

sui client call --package <PACKAGE_ID> --module firoll --function mint --args <TREASURYCAP_ID> 1000000 <RECIPIENT_ADDRESS> --gas-budget 300000000
Burn token

sui client call --package <PACKAGE_ID> --module supra --function burn --args <TREASURYCAP_ID> <Coin Object ID> --gas-budget 3000
Handling Updates and Migrations
To update your Move code or migrate to a newer version, use:

sui move migrate
more…..

Error

sui client ptb
--gas-budget 100000000
--assign sender @$MY_ADDRESS
--move-call $PACKAGE_ID::todo_list::new
--assign list
--transfer-objects "[list]" sender

[warn] Client/Server api version mismatch, client api version : 1.24.1, server api version : 1.25.0
thread '2024-05-06T03:14:23.341406Z ERROR telemetry_subscribers: panicked at crates/sui-protocol-config/src/lib.rs:1252:9:
Network protocol version is ProtocolVersion(44), but the maximum supported version by the binary is 43. Please upgrade the binary. panic.file="crates/sui-protocol-config/src/lib.rs" panic.line=1252 panic.column=9
main' panicked at crates/sui-protocol-config/src/lib.rs:1252:9:
Network protocol version is ProtocolVersion(44), but the maximum supported version by the binary is 43. Please upgrade the binary.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Aborted
run this

cargo install --locked --force --git https://github.com/MystenLabs/sui.git --branch devnet sui

gas-budget error
verify


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kxey0aqsbx7plcc3xhf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajlzc2taljo1e77rx3yj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jorukhhm4l9eq9bptpvk.png)

[](https://blog.sui.io/explorer-verified-source-code/?utm_source=twitter&utm_medium=organic&utm_campaign=build_beyond)
Tips and Trick
Using JSON Output for Better Scripting and Debugging
When deploying contracts or interacting with the Sui network, you can use the --json flag to format the output as JSON. This is particularly useful for developers who want to script interactions with the CLI and process the output programmatically.

sui client publish --package ./path_to_your_package --gas-budget 100000000 --json
Check Transaction Status
After submitting transactions, you can check their status to ensure they have been processed successfully. This is critical for operations where the state must be verified before proceeding.

sui client tx-status --digest <TX_DIGEST>
Efficiently Manage Gas and Fees
Understanding and managing gas is crucial. Use the --gas-budget parameter to specify the maximum amount of gas you're willing to spend on a transaction. This helps in avoiding unexpectedly high fees.

```sui client call --package <PACKAGE_ID> --function <FUNCTION_NAME> --args <ARGS> --gas-budget 500000```

Save Deployment Artifacts
When deploying contracts, the CLI tool can generate important artifacts such as logs or contract addresses, which are often useful for debugging or operational purposes. 
Use appropriate flags to save these outputs to a specific directory or file.

```sui client call --package <PACKAGE_ID> --module <MODULE_NAME> --function <FUNCTION_NAME> --args <ARGS> -- ````
previewPlease Give Me a Star! ⭐ ⭐ ⭐
If you find this repository useful, please consider giving it a star on GitHub. Your support is a big thank you to me and motivates me to continue developing and sharing more great content!

[](https://github.com/DoctorNasa/sui_token)