Write a Module

Create and deploy your first move module.

1

Create a new move file within the sources directory.

The sources directory holds the move modules that you will be working on within your project. Within the sources directory, create the example.move file with the following code.

example.move
module exampleAddress::transfer {

    use supra_framework::supra_coin;
    use supra_framework::coin;

    // Function to transfer the specified amount to two destinations from the source signer
    public entry fun two_by_two(
        first: &signer,
        amount_first: u64,
        dst_first: address,
        dst_second: address,
    ) {
        // Transfer the specified amount to the first destination
        coin::transfer<supra_coin::SupraCoin>(first, dst_first,amount_first);
        // Transfer the same amount to the second destination
        coin::transfer<supra_coin::SupraCoin>(first,dst_second, amount_first);
    }

     // Function to view the balance of an address
    #[view]
    public fun view_balance(address: address): u64 {
        coin::balance<supra_coin::SupraCoin>(address)
    }

}

The two_by_two function provided has four parameters. The signer, amount to be transferred, and two destination addresses. The function will transfer the passed amount to both destination addresses.

Signer is a built-in Move resource. It indicates which account is responsible for calling the transaction. This value is automatically injected by the VM and not passed by the user.

Last updated