Sui
Amit Nadiger
Polyglot(Rust??, Move, C++, C, Kotlin, Java) Blockchain, Polkadot, UTXO, Substrate, Sui, Aptos, Wasm, Proxy-wasm,AndroidTV, Dvb, STB, Linux, Cas, Engineering management.
Move is a smart contract programming language written in Rust that powers the Sui Network. It offers significant advancements in security and productivity, making it an excellent choice for building decentralized applications (dApps). Here are some key features of Move:
Gaming: Tradable in-game assets can be built using Move.
Finance: Move enables low-fee and near-instant settlement for financial applications.
Commerce: Authentic interactions and verifiable assets can be implemented using Move.
Similarities with Rust!
Key Difference :
Purpose:
Move: Designed specifically for secure smart contract development on blockchains.
Rust: General-purpose language suitable for various applications, including systems programming, web development, and embedded systems.
Execution Environment:
Move: Primarily compiled to bytecode for execution on a virtual machine within a blockchain.
Rust: Compiled directly to machine code for native execution on various platforms.
Ownership System:
Move: Ownership is transferred at compile time, offering strong guarantees against memory leaks. Borrowing allows temporary use of resources.
Rust: Ownership is enforced at compile time, but borrowing can be more flexible with explicit lifetime annotations.
Features:
Move: Focuses on resource management and safety for smart contracts. Lacks features like generics or macros present in Rust.
Rust: Offers a wider range of features like generics, macros, and advanced memory management techniques for broader application development.
Performance comparison between Rust and Move:
Move's performance is not on par with Rust's native execution:
However, it's important to consider the trade-offs:
So:
The choice between the two depends on the specific needs of the project.
The move is adaptable to meet the needs of the blockchain and the code it operates on.
The move can be customized based on the blockchain needs :
FYI:
Move on Sui contains some important differences from Move on other blockchains.
Some of the key differences with Move on Sui include:
Reference:
Sui
Sui is an account-based model: Sui transactions are processable in parallel makes it fast and efficient.
Sui has a native token called SUI : Fixed supply;
Consensus mechanism: Delegated Proof-of-Stake (DPoS) powered Byzantine fault tolerant.
Features of move and sui:
1. Object-based data models :
Building blocks on move , its just a big database of objects ,Works with scarce objects , Objacts have conservation property (cant copy , cant drop,Strong ownership transfer), Objects are notyhing but structs with unique ids. These id reamin same evene whne they are transferred from one account to another account.
“Most things in life are objects,” especially assets managed by real-world contracts. With the object data model on Sui, smart contracts mirror that reality. Object types, ownership, transfers, and display are native features. Objects are a common vocabulary throughout the stack, simplifying apps, wallets, explorers, and the overall developer experience.
2. Programmable Transaction Blocks [PTBs]
We can create programmable transaction blocks (PTBs) on Sui to perform multiple commands in a single transaction.
PTBs enable rich but safe (no re-entrance or dynamic dispatch) code composability. A single Sui transaction can call up to 1024 separate Move functions, either homogeneously for mass batching or heterogeneously where typed objects serve as inputs to the next calls. Highly expressive, heterogeneous PTBs move composition from the smart contract level to the transaction level, significantly improving gas efficiency and code simplicity. : Composiablity on the fly.
3. Dynamic fields -. Fields can be added dynamically
Dynamic fields enable safe data composability. Add or remove object fields on the fly, link objects together, and organize data via intuitive object hierarchies.
4. Security: Highly secure :
Security is achieved via following:
1. Need to write the access control checks as objects have native metadata and one of the important pieces of the metadata is the owner of the object.
2. No - Re-entrance by construction: Every time it calls the statically known functions which makes it very easy to write a predictable code . <- This removes the biggest source of hacks.
Practicals :
I did some experiments on both move and sui. I just recording them here :
Get the sui binaries from below :
FYI V1.23.1 can be replaced with latest one .
It contains below :
Functionality of each of the binaries :
How to connect the Sui client to a network, run the following command:
amit@DESKTOP-TF687VE:~$ sui client
It gives below output:
The available environment in local PC:
amit@DESKTOP-TF687VE:~/OmBlockchain/OmSui$ sui client envs
In the above my sui client is connected to devnet.
Switching the env :
sui client switch --env <ALIAS>
Ex; amit@DESKTOP-TF687VE:~/OmBlockchain/OmSui$ sui client switch --env localnet
领英推荐
How to launch the blockchain in local PC?
To start the local network, run the following command from your sui root folder.
amit@DESKTOP-TF687VE:~$ RUST_LOG="off,sui_node=info" ./sui-test-validator
The output looks like below :
For various options to strat the full node please use below command :
sui-test-validator --help
Access the local Full node using the curl:
curl --location --request POST 'https://0.0.0.0:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getTotalTransactionBlocks",
"params": []
}'
We see the output as below underlined in red color:
Building the package/smartContract & deploying in the network
When we build the smart contract for the sui, we use below command :
$ sui move build
Sui client address :
amit@DESKTOP-TF687VE:$ sui client active-address
0xa9b4ce1301c66d7c4e4f97b1292d1b97c6316aa9ef96c833cb5540a888ea5c11
Requesting Coins using the client:
amit@DESKTOP-TF687VE:$ sui client faucet
Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.
Balance checking using the client:
amit@DESKTOP-TF687VE:$ sui client balance
or we can check using objects also :
amit@DESKTOP-TF687VE:~ $ sui client objects
Publishing the move package in sui network:
The output of the command "sui client publish --gas-budget 100000000" is the transaction digest, which is a unique identifier of the transaction and can be used to query the transaction status.
Transaction Data
The section titled TransactionData contains the information about the transaction we just sent.
It features fields like sender, gas_budget set with the --gas-budget argument, and the Coin we used for payment.
Transaction Effects
Transaction Effects contains the status of the transaction, the changes that the transaction made to the state of the network and the objects involved in the transaction.
Events
If there were any events emitted, you would see them in this section. Our package does not use events, so the section is empty, as you see above.
Object Changes
These are the changes to objects that transaction has made. It has 3 sections in our case ;
Balance Changes
This last section contains changes to SUI Coins, in our case, we have spent around 0.012 SUI, which in MIST is 8275480. You can see it under the amount field in the output in the above screenshot.
Sending Transactions:
I am faced issues in sending the transactions in devnet, for which I have raised the Issue. I will update this once I resolve my issue.
I update my env to local then I am able to send the transactions:
Prepare the env Variables as below:
amit@DESKTOP-TF687VE:~$ export PACKAGE_ID=0x95a7aa2ff2b1d11f8d188ecebe62b9c90855bbeb5d78bcbb21d4d0c17824cb03
amit@DESKTOP-TF687VE:~/$ export MY_ADDRESS=$(sui client active-address)
Sending the tranmsaction:
sui client ptb \
--gas-budget 100000000 \
--assign sender @$MY_ADDRESS \
--move-call $PACKAGE_ID::todo_list::new \
--assign list \
--transfer-objects "[list]" sender
Then you will o/p as below :
In the above todo-list is created.
Now let's push some elements to the to-do list:
Passing Objects to Functions
The TodoList that we created in the previous step is an object that you can interact with as its owner. You can call functions defined in the todo_list module on this object. To demonstrate this, we will add an item to the list. First, we will add just one item, and in the second transaction, we will add 3 and remove another one.
Double-check that you have variables set up from the previous step, and then add one more variable for the list object.
export LIST_ID=0x4925ee58c94f3c6e145c9912804f2e82a071f44394dd647dbf7063905ed49769
Adding the item to list
We can push the item to the list using below commands:
sui client ptb --gas-budget 100000000 --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Jai Shree Ram'"
lets push one more item :
sui client ptb --gas-budget 100000000 --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Jai Bajrang Bali"
We can check the object id as below:
Removing the element from the list :
$--move-call $PACKAGE_ID::todo_list::remove @$LIST_ID 0
Reference :