This tutorial introduces the power of Devbox with an example of a smart contract (implemented using one of NEAR's official Fungible Tokens) that is easy to build and easy to distribute.
NEAR is a decentralized application platform that uses blockchain with sharding technology.
Disclaimer: This tutorial is only suitable for learning about smart contracts.
Fungible Tokens I'm not going to explain, if you are interested in searching for yourself, I am trying to use this thing to make a point system within the company, which can be used to reward the members of the enterprise in real time through the points.
Without further ado, it's official:
Open a Rust environment in seconds
First loginSealosThen open Devbox and select the Rust environment.
If you have to install the environment on your own computer, you may encounter the following problems:
- It takes half a day to download and doesn't always install successfully.
- It might mess up the environment and be inconvenient to push to start over.
- If you're an m-series MacBook, it's an arm64 architecture, and going live to a server is generally an x86 architecture, with all sorts of cross-platform compilations that can fuck people up.
After waiting for the status to change to Running, select Connect with Cursor in the Action Options, and the first time you open it, you will be prompted to install the Devbox plugin, which will automatically connect to the development environment.
This way the basic clean programming environment is taken care of, and the environment is all in the cloud, connected through the local Cursor.
Installing the NEAR CLI
Enter the following command in the Cursor terminal:
rustup target add wasm32-unknown-unknown
curl --proto '=https' --tlsv1.2 -LsSf //near/near-cli-rs/releases/latest/download/ | sh
curl --proto '=https' --tlsv1.2 -LsSf //near/cargo-near/releases/latest/download/ | sh
You can feel the godlike speed, especially in the overseas availability zones, theIf in the local machine, I guess the above three actions can brush half an hour of jitterbug again。
Cloning Code
git clone //fanux/FT
cd FT
# Compile the code
. /scripts/
In less than 30s, it's all done again, and there are no errors because the environment and code are so well aligned that nothing happens that isn't expected.
Create a NEAR Account
$ near login
If your browser doesn't automatically open, please visit this URL:
/login/?title=NEAR+CLI&public_key=edAi3rTjgAd5g7racV3GAkBt4RtqDjjKa1
You can then copy this link to your browser to create an account, or if you don't have an account yet, you can create a new one in TestNet.
The last 12 words must be memorized, and the mnemonics can be used to generate public and private keys.
After success you can see this file, which contains the private key, please do not disclose it:
sealos@sealospoint:~/project/FT$ ls ~/.near-credentials/testnet/
Deployment Contracts
sealos@sealospoint:~/project/FT$ ID=
sealos@sealospoint:~/project/FT$ echo $ID
near deploy $ID res/fungible_token.wasm
Issue FT
near call $ID new \
'{"owner_id": "'$ID'", "total_supply": "1000000000000000", \
"metadata": { "spec": "ft-1.0.0", "name": " Sealos Point", \
"symbol": "SLPT", "decimals": 8 }}' --accountId $ID
After that, you can see your own FTs in your wallet.
release version
If there is nothing wrong with the test code, you can use Devbox to package the entire environment:
This automatically hits you with a Docker image that is 100% successful and 100% doesn't require you to care about Dockerfile and any knowledge of Docker and K8s.
online operation
The version we just released can be run online by clicking Deploy, so we can separate our development environment from our online environment. The contracts in this tutorial run on the blockchain, so there's no need to deploy them here.
summarize
I've tried to do this before without Devbox, and the environment just didn't work out for me. Installation was particularly slow, and I had a lot of messed up stuff installed on my local machine that was prone to dependency package version conflicts.
Once compiled Rust code computer can fry eggs, ARM architecture and x86 there are still a lot of incompatible also need to engage in cross-platform compilation. It's hard to get the environment right, so I can't keep it for the next time I want to continue to use it.
After the development and to configure HTTPS database load balancing and other things, tired not love, think of writing a code to engage in so many unrelated things, I do not want to write.
However, with Devbox, all these things are done in a few minutes, and the environment is very clean and rich, the download of packages is very fast, and the compilation is directly in the cloud with no lag at all. It's a godsend!