Alva

Alva

programmer
github
telegram
email

Let's Move - Learn to Move (Part One)

letsmove

Let's Move is an incentive program for learning Move to earn SUI, encouraging more people to learn the Move language.

Learning Log (alva-lin)

Task 1 - hello move#

Basic Operations of Sui CLI#

Refer to the documentation Sui CLI: Client

Network#

  1. View the list of currently added networks
sui client envs

The output is as follows, where alias is the network alias, url is the network address, and active is the currently active network.

╭─────────┬─────────────────────────────────────┬────────╮
│ alias   │ url                                 │ active │
├─────────┼─────────────────────────────────────┼────────┤
│ devnet  │ https://fullnode.devnet.sui.io:443  │        │
│ mainnet │ https://fullnode.mainnet.sui.io:443 │        │
│ testnet │ https://fullnode.testnet.sui.io:443 │ *      │
╰─────────┴─────────────────────────────────────┴────────╯
  1. Add a network

If the previous networks do not include testnet, you can add it yourself.

sui client new-env --alias=testnet --rpc https://fullnode.testnet.sui.io:443

The output is as follows

Added new Sui env [testnet] to config.

You can run sui client envs again to check if it has been added to the list.

  1. Switch the current environment's network
sui client switch --env testnet

The output is as follows

Active environment switched to [testnet]

The output indicates that the switch was successful. You can also run sui client envs again to check if the current active network is testnet.

Address#

  1. View the address list
sui client addresses

The command and environment are similar, and the output after execution is as follows

╭──────────────────┬───────────────────────┬────────────────╮
│ alias            │ address               │ active address │
├──────────────────┼───────────────────────┼────────────────┤
│ adoring-turquois │ 0xb31fc********c57f48 │ *              │
╰──────────────────┴───────────────────────┴────────────────╯
  1. Switch the currently active address
sui client active-address

The output is as follows, directly outputting the currently active address

0xb31fc********c57f48

Compile & Publish & Call#

  1. Create a new package
sui move new 03_hello_move

This command will not produce output but will create a sui package folder in the current path, with the following contents

❯ tree 03_hello_move
03_hello_move
├── Move.toml
└── sources

1 directory, 1 file

We will place the code files in the sources folder.

Package Naming Issue:

If, like me, you start each project with a number for easy record-keeping, you will encounter an error during subsequent code compilation.

 sui move build
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING 03_hello_move
error[E01002]: unexpected token
  ┌─ sources/hello_move.move:1:11

1 module 03_hello_move::hello {
           ^^^

           Unexpected 'hello_move'
           Expected '::'

Failed to build Move modules: Compilation error.

There are two solutions:

  1. (Recommended) When creating the project, use a name without a number: sui move new hello_move, and then rename the folder: mv hello_move 03_hello_move

  2. Create the project normally, then find the [addresses] block in the Move.toml file and change 03_hello_move to hello_move. Also, note that when writing code, the package name is hello_move.

Additionally, there is a difference in the [package] block of the Move.toml file, where the name field is named directly based on the package name in sui move new <package_name>.

  1. Compile

First, navigate to the package's corresponding path, then execute the following command

sui move build

If there are no basic errors in the code, the output is as follows

UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING 03_hello_move

Also, note that a build folder and a Move.lock file have been added to the current path.

 tree -L 2
.
├── Move.lock
├── Move.toml
├── build
   ├── 03_hello_move
   └── locks
└── sources
    └── hello_move.move
  1. Publish

Before publishing, pay attention to the currently active network and address. In the package's corresponding path, execute the following command to publish the package to the corresponding network

sui client publish --gas-budget 100000000

Here, gas-budget refers to the gas fee budget for running the module initialization program.

If the publication is successful, the following content will be output. Note: The output content may vary slightly each time, but the structure is generally the same.

The output is divided into several blocks

  • Transaction Data

  • Transaction Effects

  • Transaction Events

  • Object Changes

  • Balance Changes

Find the Created Objects output information in the Transaction Effects block, where the Owner is an Immutable object, which is the published package. You can see that the corresponding package ID is 0x96ad76ea3a055760f257b839668c8c8d113502bcc04b688a35350b83a76abd15.

UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING 03_hello_move
Successfully verified dependencies on-chain against source.
Transaction Digest: FAGtpXnChnj2ZPxoZvt3kAuWY7esvPHGmpHbwAAUcdPX
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Transaction Data                                                                                             │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Sender: 0xb31fc********c57f48                                                                                │
│ Gas Owner: 0xb31fc********c57f48                                                                             │
│ Gas Budget: 100000000 MIST                                                                                   │
│ Gas Price: 1000 MIST                                                                                         │
│ Gas Payment:                                                                                                 │
│  ┌──                                                                                                         │
│  │ ID: 0x91cbd3fe3422844d015fa2a7da45721d42226cd2cd6c54f2a5097a8679fc678b                                    │
│  │ Version: 920427                                                                                           │
│  │ Digest: Gucz8kmhru994mu1SMfsrasg3YjsPkzscj5KKkEmxu4X                                                      │
│  └──                                                                                                         │
│                                                                                                              │
│ Transaction Kind: Programmable                                                                               │
│ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ Input Objects                                                                                            │ │
│ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ 0   Pure Arg: Type: address, Value: "0xb31fc********c57f48                                             " │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ ╭─────────────────────────────────────────────────────────────────────────╮                                  │
│ │ Commands                                                                │                                  │
│ ├─────────────────────────────────────────────────────────────────────────┤                                  │
│ │ 0  Publish:                                                             │                                  │
│ │  ┌                                                                      │                                  │
│ │  │ Dependencies:                                                        │                                  │
│ │  │   0x0000000000000000000000000000000000000000000000000000000000000001 │                                  │
│ │  │   0x0000000000000000000000000000000000000000000000000000000000000002 │                                  │
│ │  └                                                                      │                                  │
│ │                                                                         │                                  │
│ │ 1  TransferObjects:                                                     │                                  │
│ │  ┌                                                                      │                                  │
│ │  │ Arguments:                                                           │                                  │
│ │  │   Result 0                                                           │                                  │
│ │  │ Address: Input  0                                                    │                                  │
│ │  └                                                                      │                                  │
│ ╰─────────────────────────────────────────────────────────────────────────╯                                  │
│                                                                                                              │
│ Signatures:                                                                                                  │
│    Hl+Chc7V72WhwKAwJ3T8PrhCibN9T27nZMNmVFpN7FqiTBPSVbxYfL+B5uyp3oRQ463WjGA8/oJ0cxmRfz92BA==                  │
│                                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Transaction Effects                                                                               │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Digest: FAGtpXnChnj2ZPxoZvt3kAuWY7esvPHGmpHbwAAUcdPX                                              │
│ Status: Success                                                                                   │
│ Executed Epoch: 318                                                                               │
│                                                                                                   │
│ Created Objects:                                                                                  │
│  ┌──                                                                                              │
│  │ ID: 0x96ad76ea3a055760f257b839668c8c8d113502bcc04b688a35350b83a76abd15                         │
│  │ Owner: Immutable                                                                               │
│  │ Version: 1                                                                                     │
│  │ Digest: 2iv1DT3ARdBDwowswWA87ucPubfbEXfYkrcM1R6QyxWd                                           │
│  └──                                                                                              │
│  ┌──                                                                                              │
│  │ ID: 0xea782e392b95749ab43c20d9902f19b2976226391bdbd70e81f380f079932460                         │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              )  │
│  │ Version: 920428                                                                                │
│  │ Digest: 6kC43pZb8YDZ9BDisXc3fmktSWt9PxP13N4QNa1sLank                                           │
│  └──                                                                                              │
│ Mutated Objects:                                                                                  │
│  ┌──                                                                                              │
│  │ ID: 0x91cbd3fe342284d015fa2a7da45721d42226cd2cd6c54f2a5097a8679fc678b                         │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              )  │
│  │ Version: 920428                                                                                │
│  │ Digest: CDN8E9EuPNgtwiLF77ZxAdx8BXMw27uQzcG1ADxuG9fZ                                           │
│  └──                                                                                              │
│ Gas Object:                                                                                       │
│  ┌──                                                                                              │
│  │ ID: 0x91cbd3fe342284d015fa2a7da45721d42226cd2cd6c54f2a5097a8679fc678b                         │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              )  │
│  │ Version: 920428                                                                                │
│  │ Digest: CDN8E9EuPNgtwiLF77ZxAdx8BXMw27uQzcG1ADxuG9fZ                                           │
│  └──                                                                                              │
│ Gas Cost Summary:                                                                                 │
│    Storage Cost: 7539200 MIST                                                                     │
│    Computation Cost: 1000000 MIST                                                                 │
│    Storage Rebate: 978120 MIST                                                                    │
│    Non-refundable Storage Fee: 9880 MIST                                                          │
│                                                                                                   │
│ Transaction Dependencies:                                                                         │
│    27si9MdVQzBrEzHWrbZJThtB7nVSHC1x14EuE5r3o2V2                                                   │
│    GZcMfNx5jvGHsfSKEHJD7jZss7yCHqEGfhVk8Jx8a2N1                                                   │
│    HuSWWnS6ZXZyyBpyoaWf7b8N961SPMUW7q9apQ5VkJTr                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────╮
│ No transaction block events │
╰─────────────────────────────╯

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Object Changes                                                                                   │
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Created Objects:                                                                                 │
│  ┌──                                                                                             │
│  │ ObjectID: 0xea782e392b95749ab43c20d9902f19b2976226391bdbd70e81f380f079932460                  │
│  │ Sender: 0xb31fc********c57f48                                                                 │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              ) │
│  │ ObjectType: 0x2::package::UpgradeCap                                                          │
│  │ Version: 920428                                                                               │
│  │ Digest: 6kC43pZb8YDZ9BDisXc3fmktSWt9PxP13N4QNa1sLank                                          │
│  └──                                                                                             │
│ Mutated Objects:                                                                                 │
│  ┌──                                                                                             │
│  │ ObjectID: 0x91cbd3fe342284d015fa2a7da45721d42226cd2cd6c54f2a5097a8679fc678b                  │
│  │ Sender: 0xb31fc********c57f48                                                                 │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              ) │
│  │ ObjectType: 0x2::coin::Coin<0x2::sui::SUI>                                                    │
│  │ Version: 920428                                                                               │
│  │ Digest: CDN8E9EuPNgtwiLF77ZxAdx8BXMw27uQzcG1ADxuG9fZ                                          │
│  └──                                                                                             │
│ Published Objects:                                                                               │
│  ┌──                                                                                             │
│  │ PackageID: 0x96ad76ea3a055760f257b839668c8c8d113502bcc04b688a35350b83a76abd15                 │
│  │ Version: 1                                                                                    │
│  │ Digest: 2iv1DT3ARdBDwowswWA87ucPubfbEXfYkrcM1R6QyxWd                                          │
│  │ Modules: hello                                                                                │
│  └──                                                                                             │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Balance Changes                                                                                   │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│  ┌──                                                                                              │
│  │ Owner: Account Address ( 0xb31fc********c57f48                                              )  │
│  │ CoinType: 0x2::sui::SUI                                                                        │
│  │ Amount: -7561080                                                                               │
│  └──                                                                                              │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
  1. Call a function

We can call the say_hello function from the contract we just published to obtain an object.

First, save the package ID we just obtained as a variable

export PACKAGE_ID=<package object ID>

Then use the relevant command

sui client call --package $PACKAGE_ID --module hello --function say_hello --gas-budget 300000000

If executed correctly, the following content will be output.

Similarly, we find the Created Objects in the Transaction Effects block, and this time only one object is created, with the corresponding ID 0xc3eb50f39ec09e4e2eed994fdf60f855f4841b3591c94ca85e54047ed105280d.

Transaction Digest: 3Ys1pYtBSgUiXUYMsK37KPWftcXX5icbbPLgT1f1frPp
╭──────────────────────────────────────────────────────────╮
│ Transaction Data                                         │
├──────────────────────────────────────────────────────────┤
│ Sender: 0xb31fc********c57f48                            │
│ Gas Owner: 0xb31fc********c57f48                         │
│ Gas Budget: 300000000 MIST                               │
│ Gas Price: 1000 MIST                                     │
│ Gas Payment:                                             │
│  ┌──                                                     │
│  │ ID: 0x91cbd3fe34228********cd26c54f2a5097a8679fc678b  │
│  │ Version: 920429                                       │
│  │ Digest: BgNZWUPLdG1WNxupJjP8R1RbQdqHYmLYP8GXYHEX2bg   │
│  └──                                                     │
│                                                          │
│ Transaction Kind: Programmable                           │
│   No input objects for this transaction                  │
│ ╭────────────────────────────────────────────────────╮   │
│ │ Commands                                           │   │
│ ├────────────────────────────────────────────────────┤   │
│ │ 0  MoveCall:                                       │   │
│ │  ┌                                                 │   │
│ │  │ Function:  say_hello                            │   │
│ │  │ Module:    hello                                │   │
│ │  │ Package:   0x96ad76ea3a055****a35350b83a76abd15 │   │
│ │  └                                                 │   │
│ ╰────────────────────────────────────────────────────╯   │
│                                                          │
│ Signatures:                                              │
│    FlBbaPmrMt9DNKt9EMug********R8KcJes7dzem52d2CDkFcBA== │
│                                                          │
╰──────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────╮
│ Transaction Effects                                      │
├──────────────────────────────────────────────────────────┤
│ Digest: 3Ys1pYtBSgUiXUYMsK37KPWftcXX5icbbPLgT1f1frPp     │
│ Status: Success                                          │
│ Executed Epoch: 318                                      │
│                                                          │
│ Created Objects:                                         │
│  ┌──                                                     │
│  │ ID: 0xc3eb50f39ec09e4e2e****91c94ca85e54047ed105280d  │
│  │ Owner: Account Address ( 0xb31fc********c57f48      ) │
│  │ Version: 920430                                       │
│  │ Digest: ZmguJw2kjwwrFYUYuZ8xG4EZcHc6n2CjMibhc9CjYNr   │
│  └──                                                     │
│ Mutated Objects:                                         │
│  ┌──                                                     │
│  │ ID: 0x91cbd3fe342284d********c54f2a5097a8679fc678b   │
│  │ Owner: Account Address ( 0xb31fc********c57f48      ) │
│  │ Version: 920430                                       │
│  │ Digest: 74GDCP91puviUXMmMFv7EEYSkuP7uMTt4MaPxGJi3JRj  │
│  └──                                                     │
│ Gas Object:                                              │
│  ┌──                                                     │
│  │ ID: 0x91cbd3fe342284d******2cd6c54f2a5097a8679fc678b │
│  │ Owner: Account Address ( 0xb31fc********c57f48      ) │
│  │ Version: 920430                                       │
│  │ Digest: 74GDCP91puviUXMmMFv7EEYSkuP7uMTt4MaPxGJi3JRj  │
│  └──                                                     │
│ Gas Cost Summary:                                        │
│    Storage Cost: 2340800 MIST                            │
│    Computation Cost: 1000000 MIST                        │
│    Storage Rebate: 978120 MIST                           │
│    Non-refundable Storage Fee: 9880 MIST                 │
│                                                          │
│ Transaction Dependencies:                                │
│    65HTDLBC9h1cTbdPcuDPRpL3ZJUGvgWZHaQSpVcnos2R          │
│    FAGtpXnChnj2ZPxoZvt3kAuWY7esvPHGmpHbwAAUcdPX          │
╰──────────────────────────────────────────────────────────╯
╭─────────────────────────────╮
│ No transaction block events │
╰─────────────────────────────╯

╭──────────────────────────────────────────────────────────╮
│ Object Changes                                           │
├──────────────────────────────────────────────────────────┤
│ Created Objects:                                         │
│  ┌──                                                     │
│  │ ObjectID: 0xc3eb50****47ed105280d                     │
│  │ Sender: 0xb31fc********c57f48                         │
│  │ Owner: Account Address ( 0xb31fc********c57f48      ) │
│  │ ObjectType: 0x96ad76****0b83a76abd15::hello::Hello    │
│  │ Version: 920430                                       │
│  │ Digest: ZmguJw2kjwwrFYUYuZ8xG4EZcHc6n2CjMibhc9CjYNr   │
│  └──                                                     │
│ Mutated Objects:                                         │
│  ┌──                                                     │
│  │ ObjectID: 0x91cbd3fe342284****a5097a8679fc678b        │
│  │ Sender: 0xb31fc********c57f48                         │
│  │ Owner: Account Address ( 0xb31fc********c57f48      ) │
│  │ ObjectType: 0x2::coin::Coin<0x2::sui::SUI>            │
│  │ Version: 920430                                       │
│  │ Digest: 74GDCP91puviUXMmMFv7EEYSkuP7uMTt4MaPxGJi3JRj  │
│  └──                                                     │
╰──────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────╮
│ Balance Changes                                          │
├──────────────────────────────────────────────────────────┤
│  ┌──                                                     │
│  │ Owner: Account Address ( 0xb31fc********c57f48     )  │
│  │ CoinType: 0x2::sui::SUI                               │
│  │ Amount: -2362680                                      │
│  └──                                                     │
╰──────────────────────────────────────────────────────────╯

Sui Browser Wallet#

These two wallets are currently only available as browser extensions

Sui Explorer & SuiScan#

Sui block explorers allow you to view any records on the chain by providing an address or ID.

Taking suiscan as an example, we previously used sui client call ... to call the function from the contract we just published, obtaining an object ID. We can directly use the format https://suiscan.xyz/<env>/object/<object ID> to see the information of this newly created object. Alternatively, you can also input the package ID to see related information.

Here is the package link:
https://suiscan.xyz/testnet/object/0x96ad76ea3a055760f257b839668c8c8d113502bcc04b688a35350b83a76abd15

Here is the hello object link:
https://suiscan.xyz/testnet/object/0xc3eb50f39ec09e4e2eed994fdf60f855f4841b3591c94ca85e54047ed105280d

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.