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

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

  1. Add a network

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

The output is as follows

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

  1. Switch the current environment's network

The output is as follows

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

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

  1. Switch the currently active address

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

Compile & Publish & Call#

  1. Create a new package

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

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.

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

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

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

  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

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.

  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

Then use the relevant command

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.

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.