Series Article Directory#
Task1: hello move🚪
Task2: move coin🚪
Task3: move nft🚪
Task4: move game🚪
More exciting content, stay tuned!✌️
@[TOC](Article Directory)
Preface#
With the rapid development of blockchain technology, more and more developers are seeking more efficient and secure blockchain platforms to support the rapid development of decentralized applications (DApps). Sui Chain and Move programming language are emerging blockchain solutions that, with their innovative design concepts and technical advantages, are becoming ideal choices for developing high-performance blockchain applications.
This article will introduce the basic concepts and advantages of Sui Chain and Move programming language, as well as how they are changing the way blockchain applications are developed. Through the Task1 task in the Move co-learning activity, we will help everyone quickly get started and practice deploying the first Move contract.
What is Sui Chain?#
Sui is a high-performance blockchain platform designed to provide fast, secure, and scalable infrastructure for decentralized applications. It was developed by the Aptos Labs team and is based on a new consensus protocol—Narwhal & Tusk. The design goal of Sui is to solve the performance bottlenecks of blockchain, providing extremely high transaction throughput and low latency to meet the needs of complex application scenarios.
Main features of Sui Chain:
-
High throughput and low latency: Sui's consensus mechanism allows for the parallel processing of a large number of transactions without waiting for global consensus across the entire network. This parallel design can achieve thousands of transactions per second, greatly improving the throughput of the blockchain and reducing transaction confirmation delays.
-
Object-oriented resource management: Sui treats resources in the blockchain as objects for management. These resources (such as tokens, NFTs) have independent identifiers that can be directly tracked and manipulated. This way, Sui can efficiently and parallelly process resources across multiple nodes without handling global state, further enhancing performance.
-
Flexible transaction model: Sui provides a flexible and efficient transaction model that supports parallel execution of transactions across multiple resource objects. This means that transactions from different users can be conducted independently and efficiently, avoiding performance bottlenecks typical of traditional blockchains.
-
Efficient account and permission management: Sui offers a diverse account management mechanism that can handle complex permission requirements in decentralized applications. Whether it is a personal account, a smart contract account, or a multi-signature account, they can be flexibly configured and managed.
What is Move Programming Language?#
Move is a programming language designed specifically for blockchain development, initially developed by the MetaLibra (later Diem) team and later adopted by the Sui blockchain. The design focus of Move is on resource management, ownership control, and type safety, making it particularly suitable for handling assets and digital resources in decentralized applications.
Main features of Move language:
-
Resource type system: The Move language treats all resources (such as tokens, NFTs, data in smart contracts, etc.) as "resource types." These resources cannot be copied or destroyed in the system; they can only be transferred or borrowed. This ensures the uniqueness and security of each resource, fundamentally avoiding resource loss and duplicate transfer issues in traditional smart contracts.
-
Ownership and borrowing mechanism: Move manages resources through strict ownership and borrowing mechanisms. Each resource has a unique owner, and borrowing of resources must be explicitly declared, which avoids security risks when "sharing resources." Borrowing resources ensures that developers can share and manipulate resources without modifying ownership.
-
Modular programming: Move supports a modular programming structure, where each module can contain different resource types and functions. Modular design makes the code clearer, more reusable, and helps improve development efficiency and reduce the likelihood of coding errors.
-
Type safety and verifiability: Move is a strongly typed language, meaning developers must explicitly define the type of each variable and resource at compile time. Move's type system can ensure that most errors in contracts are discovered during the compilation phase, thus avoiding runtime errors and enhancing the security of smart contracts.
Example code in Move language:
Here is a simple Move contract example that demonstrates how to create and transfer a resource called Coin
:
address 0x1 {
module CoinModule {
resource struct Coin has store {
value: u64,
}
public fun create_coin(value: u64): Coin {
Coin { value }
}
public fun transfer_coin(coin: Coin, recipient: address): Coin {
let new_coin = Coin { value: coin.value };
// Here you can perform the actual transfer operation
return new_coin;
}
}
}
In this example, Coin
is a resource type that contains a value
field representing the value of the token. The create_coin
function is used to create a new Coin
resource, while the transfer_coin
function is used to transfer the Coin
resource to a specified account.
Move Co-learning Activity: Quick Start with Move Development#
To help more developers quickly understand and master the Move programming language, the Move Co-learning activity is jointly initiated by HOH Community, HackQuest, OpenBuild, and KeyMap. This activity aims to provide a good learning platform for beginners, guiding everyone step by step to become familiar with the Move language and understand how to apply it to Web3 development.
By collaborating with professional mentors in the Move field, participants can quickly grasp the basics of the Move language and gradually advance to more complex application development. Whether you are a blockchain beginner or an engineer with some development experience, you can benefit from this.
Resource links:
- Official Sui Documentation🚪: Get detailed documentation about Sui Chain, including development guides, API references, etc.
- Move Learning Bilibili Video🚪: Follow along with video tutorials on Bilibili to learn the basics and advanced topics of the Move programming language.
- Letsmove Repository🚪: This is a GitHub repository for Move learning resources, containing various example codes and tutorials to help developers master the Move language.
I. Install Sui Environment#
Sui Official Installation Tutorial🚪
To develop Sui blockchain applications, you first need to install the Sui development environment. Here are the steps to install the Sui environment on Windows:
1. Download and Unzip Sui#
First, visit the Sui environment's GitHub repository🚪, and find the release version in the bottom right corner.
In the Assets section of the version, select the corresponding .tgz
compressed file for the Windows operating system, download and unzip it.
2. Configure Environment Variables#
After unzipping, configure the environment variables. Search for advanced system settings on your computer and click on environment variables.
In the system variables, find the Path variable, add the path of the folder where you just unzipped sui, and keep clicking "OK" until you close the advanced system settings.
In the cmd command line, enter the command sui --version
to check if the installation was successful.
II. Install VSCode Plugins#
To facilitate the development of Move contracts, we recommend installing the VSCode editor and the Move plugin. With the plugin, you can enjoy syntax highlighting, code completion, contract debugging, and other features to improve development efficiency.
Installation Steps:
- Open VSCode, go to the extension store (shortcut:
Ctrl+Shift+X
), search formove
, and install the following two plugins.
- After the plugin installation is complete, you need to configure the settings to use it.
Setlint
toall
, and click Edit insettings.json
.
Modify the settings as follows, where the paths forserver.path
andsui.path
are the paths from the first step when you unzipped Sui.
- After completing the settings, restart the VSCode editor to ensure the plugins take effect.
III. Using Sui Wallet Suiet#
Before deploying contracts on the Sui testnet, you need to prepare a wallet to manage Sui tokens and pay transaction fees. Suiet is an implementation of the Sui wallet that can be used to easily manage and transfer Sui tokens.
1. Download Suiet Wallet#
Visit the Suiet download link🚪 to install.
2. Create Suiet Wallet#
After installing and launching the wallet, create a new wallet and remember the wallet's mnemonic phrase (for wallet recovery).
3. Obtain Sui Tokens#
Get test SUI tokens: Use the Sui Faucet to obtain free test tokens for paying contract deployment and transaction fees. After entering the wallet, switch the network to testnet
, then click Faucet
to obtain test SUI.
IV. Deploying the First Move Contract (HelloMove)#
Now that we have installed the Sui environment, VSCode plugins, and configured the wallet, let's write and deploy the first Move contract.
1. Pull the Code#
Pull the code from the letsmove repository🚪.
PS: It is best to use SSH to pull the code, as the code is large and using HTTPS may result in errors; SSH is more stable. For detailed configuration of SSH, please refer to section 3.1🚪.
git clone [email protected]:move-cn/letsmove.git
Copy a copy of the /mover/001
folder into the mover
folder and modify it to your own GitHub ID, for example, huahuahua1223
is my GitHub ID.
2. Create a New Project#
First, use Sui CLI to create a new Move project in the code/task1/
folder:
sui move new hello_move
This command will create a new hello_move
directory in the current directory, containing a basic Move project template:
3. Deploy the Contract#
Step One: Enter the hello_move
project directory. The first time you enter sui client publish
, it will create an account for deploying contracts.
Step Two: Enter "y"
, "Enter"
, and "0"
in sequence to generate an account with a mnemonic phrase.
Step Three: To deploy the contract on the testnet, you will need some test tokens (SUI), which can be obtained through Sui's Faucet feature: sui client faucet
, or you can import the generated account into the Suiet wallet and use the Faucet button to obtain test tokens.
Step Four: Check the current deployment account address. Before deploying the contract, you can check your account balance to ensure you have enough SUI tokens to pay for transaction fees:
sui client addresses
sui client gas
Step Five: Deploy the contract.
Now, you can deploy the Move contract to the Sui testnet. Use the following command to publish the contract:
sui client publish --gas-budget 100000000
This command will deploy the hello_move
contract to the Sui testnet and consume a certain amount of SUI tokens as fees.
The returned information includes Transaction Data, Transaction Effects, Transaction Block Events, Object Changes, and Balance Changes.
Find the PackageID
in Object Changes and check it in the Sui Blockchain Explorer🚪. If you can find the result, it means you have successfully deployed your first Move contract 🎉🎉🎉.
4. Submit Code#
For the remaining details on submitting PRs, please refer to Shocking! Contributing to open-source code is so simple, you can get started in no time!🚪
Summary#
Through this article, we have detailed how to set up a development environment in Sui and quickly get started with using the Move programming language to write and deploy smart contracts. The article starts with the installation and configuration of Sui Chain, gradually explaining how to set up the development environment, install necessary tools and plugins, and how to create and deploy the first Move contract. We also explored the high throughput and low latency features of Sui Chain, as well as the advantages of the Move programming language in resource management and security. Through practical steps and code examples, this article has helped you quickly grasp the basics of Sui blockchain development.
If you want to further improve your Move programming skills, you can join the Move co-learning activity and grow quickly through interaction with mentors and community members. I hope this blog helps you get started with Sui and Move development, and I wish you all the best on your blockchain development journey! If you have any questions or suggestions, feel free to leave a comment for discussion 🌹
More exciting content, welcome to follow the series article directory!
We grow together on the road of exploring Move, see you there! 🎉