Sui Module

πŸš€ Your First Sui Module on M2 using Movement CLI

Install the Movement CLI

bash <(curl -fsSL https://raw.githubusercontent.com/movemntdev/M1/main/scripts/install.sh) --latest

Initialize your environment

You can now create a new sui move project with the following command:

movement sui move new hello_world

This will give you a folder to access into:

cd hello_world

Open it in your favorite editor:

code .

Create your move file:

touch sources/hello_world.move

Now you have the following folder structure:

/ sources
    hello_world.move
Move.toml

Inside hello_world.move you can paste the following code:

#[lint_allow(self_transfer)]

module hello_world::hello_world {

    use std::string;
    use sui::object::{Self, UID};
    use sui::transfer;
    use sui::tx_context::{Self, TxContext};

    struct HelloWorldObject has key, store {
        id: UID,
        text: string::String
    }

    public fun mint(ctx: &mut TxContext) {
        let object = HelloWorldObject {
            id: object::new(ctx),
            text: string::utf8(b"Hello World!")
        };
        transfer::public_transfer(object, tx_context::sender(ctx));
    }

}

After building your project, you can deploy it to the M2 testnet:

movement sui client publish --gas-budget 20000000

The object ID under the Published Objects section is the ID of your module. You can now call the mint function on your module with that object ID:

movement sui client call --function mint --module hello_world --package <package object ID> --gas-budget 10000000

Don't forget to replace <package object ID> with the object ID of your module from previous console output!

Congratulations! You have just written, published, and executed your first SuiMove module on the testnet!

Last updated