Quick Start to build on SUI

TLDR:

  1. Installing the SUI Move command-line interface (CLI) tool on your machine. You can download the CLI tool from the SUI Move GitHub repository.
  2. Once you have installed the CLI tool, you will need to set up a new SUI account or use an existing one to authenticate with the network. You can do this by running the move account create command and following the prompts to create a new account or authenticate with an existing one.
  3. Next, you will need to configure the CLI tool to connect to the SUI network. This can be done by running the move network add command and specifying the network's endpoint URL.
  4. After you have configured the CLI tool, you can start interacting with the SUI network by running various commands, such as deploying smart contracts, minting tokens, and transferring assets.
  5. NodeReal RPC endpoints can be used to connect with the SUI network easily.

Install SUI

Before you start building the first step is to install SUI, and configure your local environment to connect with the SUI network.

Prerequisites

MacOS

Assuming you are using a macOS operating system, you can install these packages using the following commands in the terminal:

To install brew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

To install cURL:

brew install curl

To install Git CLI:

brew install git

To install official compiler for the Rust and its package manager Cargo (default):

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Press 1 during installation to install from default.

📘

For other operating systems, please refer to the SUI installation documentation for details.

Node & Wallet (SUI Client) installation

cargo install --locked --git https://github.com/MystenLabs/sui.git --branch "<relevant branch, main/testnet/etc>" sui

Run the following command to install Sui binaries from the devnet branch:

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

Run the following command to install Sui binaries from the mainnet branch:

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

📘

Be patient, it may take 15-60 mins to finish the compilation and installation.

Check your installation:

sui --version

sui 0.33.0-f65b02ccc

If you are using mainnet, your version will be like 1.0.0

Quick Start

Create new environment

To add a new alias for a custom RPC endpoint, run the following command. Replace values in < > with values for your installation:

sui client new-env --alias <ALIAS> --rpc <RPC-SERVER-URL>

Configure SUI with devnet RPC:

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

Configure SUI with NodeReal Mainnet RPC:

sui client new-env --alias nodereal-mainnet --rpc https://sui-mainnet-rpc.nodereal.io:443

Added new Sui env [nodereal-mainnet] to config.

Create Account

sui client new-address secp256k1

Created new keypair for address with scheme Secp256k1: [0xb04a65dcf0ff4d8f903610f0d18312f3b9ad32e30b29450db6cd537f2397a0b6]
Secret Recovery Phrase : [feel have hair powder rely mail duck deposit hundred across weasel limit]

Deploy your first Smart Contract through NodeReal RPC

Before you publish your package to mainnet, you may want to switch to devnet. You can add the devnet environment by command below.

Switch to devnet:

sui client switch --env devnet

Active environment switched to [devnet].

Identify your address through either the Sui Wallet browser extension or by running the following command and electing to connect to a Sui RPC server if prompted:

sui client active-address

0x3e3127242d3de943261ef490f214b4c291700d0dd07a857232f9122941ce60ef

Claim Gas Tokens from Faucet

Claim test tokens through cURL:

curl --location --request POST 'https://faucet.devnet.sui.io/gas' \                      
--header 'Content-Type: application/json' \
--data-raw '{
    "FixedAmountRequest": {
        "recipient": "{YOUR-SUI-ACCOUNT}"
    }
}'

For example:

curl --location --request POST 'https://faucet.devnet.sui.io/gas' \                      
--header 'Content-Type: application/json' \
--data-raw '{
    "FixedAmountRequest": {
        "recipient": "0x3e3127242d3de943261ef490f214b4c291700d0dd07a857232f9122941ce60ef"
    }
}’

Install Visual Studio Code with the move-analyzer extension.

cargo install --git https://github.com/move-language/move move-analyzer --branch sui-move --features "address32"

For more IDE options in the Awesome Move documentation.

Create Package

Create a folder and open with Visual Studio Code. To create a package named "hello_world":

sui move new hello_world

Here is just an example of the hello_word package:

├── hello_world
│   ├── Move.lock
│   ├── Move.toml
│   └── sources
│       └── hello_world.move

Change rev = "testnet" to "devnet". Move.toml is the configuration of the package:

[package]
name = "hello_world"
version = "0.0.1"


[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" }


[addresses]
hello_world =  "0x0"
sui =  "0x2"

When deploying to SUI mainnet, change rev = "testnet" to "main".


Edit from hello-world.move file

Import the smart contract code in:

module hello_world::hello_world {


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


   /// An object that contains an arbitrary string
   struct HelloWorldObject has key, store {
       id: UID,
       /// A string contained in the object
       text: string::String
   }


   public entry 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));
   }


}

Build the contract

cd hello_world
sui move build

Response:

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

Publish the package

Before you publish, you need to check your current balance of SUI token to make sure you have enough gas to pay for the transaction.

sui client gas

Response:

                           Object ID                              |  Gas Value 
----------------------------------------------------------------------------------
 0x3260f95fce732c8bc757ca3648a905e2c06a86cf590a5bb06def42d711f08e58 | 10000000000
 0xa3b57112fa2117f32ee992707bb56b0d1b2a58c5e084e422119118db9a23486b | 10000000000
 0xf013b4be90a2bef81fb4758663c6df38b72346cc2b2bf0647b6c5f891691eab8 | 10000000000

Return back to previous folder:

cd ..

Then use SUI publish command to publish the package to the ledger.

sui client publish hello_world --gas-budget 10000000

Response:

UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING hello_world
Successfully verified dependencies on-chain against source.
----- Transaction Digest ----
CLEoGe3zMwS3FWTU9j8kAKBu3Vv2i519JUEXZwQLfKNU
----- Transaction Data ----
Transaction Signature: [Signature(Ed25519SuiSignature(Ed25519SuiSignature([0, 71, 239, 34, 222, 32, 104, 191, 13, 164, 45, 173, 25, 173, 56, 78, 59, 132, 183, 160, 159, 157, 24, 42, 45, 136, 119, 161, 33, 95, 137, 72, 239, 192, 192, 250, 9, 128, 229, 32, 188, 80, 38, 48, 13, 196, 173, 115, 235, 121, 124, 152, 36, 161, 175, 20, 230, 168, 68, 46, 199, 174, 110, 14, 13, 65, 93, 88, 3, 231, 200, 219, 160, 222, 145, 137, 141, 210, 86, 187, 164, 183, 21, 148, 52, 149, 48, 49, 111, 70, 37, 228, 27, 217, 167, 204, 218])))]
Transaction Kind : Programmable
Inputs: [Pure(SuiPureValue { value_type: Some(Address), value: "0xad8634acd6123e1ce38110e0839d20260204b19a921881eb1e29f1ecc92b7865" })]
Commands: [
 Publish(_,0x0000000000000000000000000000000000000000000000000000000000000001,0x0000000000000000000000000000000000000000000000000000000000000002),
 TransferObjects([Result(0)],Input(0)),
]


Sender: 0xad8634acd6123e1ce38110e0839d20260204b19a921881eb1e29f1ecc92b7865
Gas Payment: Object ID: 0x1e15311625e13afedbaee3bbcb044c0b88acaaec35ef794a525200564b50ed90, version: 0x5846, digest: B5imiFeNBZkcS7rqNpTxpYrDoACZYdB1Bjc3FiMHVq5M
Gas Owner: 0xad8634acd6123e1ce38110e0839d20260204b19a921881eb1e29f1ecc92b7865
Gas Price: 1000
Gas Budget: 10000000


----- Transaction Effects ----
Status : Success
Created Objects:
 - ID: 0xa60d93fd7bae45566d7f793a0848b49a6dddeecb4250704c60946b34180fba55 , Owner: Immutable
 - ID: 0xb710e4aef7d5774b292f94dafe93bb909b6a57a6dfa9663c44e1f87933dfb6a4 , Owner: Account Address ( 0xad8634acd6123e1ce38110e0839d20260204b19a921881eb1e29f1ecc92b7865 )
Mutated Objects:
 - ID: 0x1e15311625e13afedbaee3bbcb044c0b88acaaec35ef794a525200564b50ed90 , Owner: Account Address ( 0xad8634acd6123e1ce38110e0839d20260204b19a921881eb1e29f1ecc92b7865 )

You need to make record of the package ID, which is “created objects”, in our case, it is 0xa60d93fd7bae45566d7f793a0848b49a6dddeecb4250704c60946b34180fba55.

Call the function of published module

You need to specify:

  • package id
  • module name
  • function name

In our case, we are going to call:

  • package id: 0xa60d93fd7bae45566d7f793a0848b49a6dddeecb4250704c60946b34180fba55
  • module name: hello_world
  • function name: mint
sui client call --package 0xa60d93fd7bae45566d7f793a0848b49a6dddeecb4250704c60946b34180fba55 --module hello_world --function mint --gas-budget 10000000

NodeReal Network info

Nodereal mainnet rpc endpoint: https://sui-mainnet-rpc.nodereal.io:443