NEAR Blockchain - Part 2, Setup your environment !!
If you are new to NEAR and want to learn and build Dapps on it, check our previous articles here 👇
As we have discussed in the previous articles, Smart contracts on NEAR can be built using “Rust” or “AssemblyScript”. Both are compiled into web assembly when we deploy the contract.
Overview
Let’s see what we need to do to get our Dapp to working state
- Deploying smart contract — It’s similar to deploying or backend with all the functions and logic written on it. This will give us a contract id that can be used to interact with it.
- Storage — As our contract will be deployed, we will have some kind of storage function too. It will be similar to the data structures used in programming. They are used to define “How data will be stored”.
- Transaction Fee — Everything that changes or updates data to blockchain is called transactions. And these transactions cost some fees for their operations. This fee is generally known as “GAS” or “GAS Fee”.
- Blockchain Environment — On NEAR, the data is being verified in a temporary VM(Virtual Machine). The VM executes the WASM code, gives output and is removed after this process.
Setting the development environment !!
Firstly Install rust if you haven't, use this to set up the dev environment.
Let’s just into compiling everything and start using these tools.
Go to your preferred location and open command line to terminal. Now just run this to start a new Rust project
cargo new blocktrain-near --lib// Replace the 'blocktrain-near' with the name of your choice.
You will see two files and one folder in the repo, one id ‘gitignore’ that contains files that need to be ignored while pushing and other is ‘cargo.toml’ that is similar to package.json in javascript project. It will contain the list of packages that we will use in our project.
‘src’ file will be the entry point for our program. It will contain lib.rs
Now change the lib.rs
content to this https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs
Find the code Breakdown here ⬇️
I know docs can be boring sometimes but it’s important to check them because they are the starting point for building !!
Read ‘How the code works and what each variable means in the above docs, we will be building our own Dapp in the next article. Stay Tuned and follow BlockTrain: Learn Web3
Roadmaps: https://blocktrain.info/roadmaps
Dev related: https://blocktrain.info/developer
Non dev related: https://blocktrain.info/non-developer
Hindi stuff: https://blocktrain.info/hindi
Chains: https://blocktrain.info/chains