DEV Community

Cover image for How to set up Rust and NEAR for Blockchain/Web3 Development
Chris Achinga
Chris Achinga

Posted on

How to set up Rust and NEAR for Blockchain/Web3 Development

Near protocol is a decentralized application platform that gives developer-friendly features to build and develop smart contracts.

Near offers the platform to build smart contracts in Rust and deploy them. By default, Near supports Rust and AssemblyScript. Rust is recommended for its greater developer experience when it comes to memory allocation and a minimal runtime, among other great reasons.

Installing Rust (Ubuntu/Linux)

To install Rust, follow the steps below:

Install Curl

If you don't have curl installed, use the scripts below:

sudo apt update
sudo apt install curl
Enter fullscreen mode Exit fullscreen mode

Install Rust

To install Rust, paste and run the script below on your terminal:

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

Configure your shell using:

source $HOME/.cargo/env
Enter fullscreen mode Exit fullscreen mode

To confirm a successful installation, run the following in a terminal:

rustup
Enter fullscreen mode Exit fullscreen mode

After that, run

sudo apt-get install build-essential
Enter fullscreen mode Exit fullscreen mode

Add wasm target to your toolchain

rustup target add wasm32-unknown-unknown
Enter fullscreen mode Exit fullscreen mode

To test out for the installation, create a simple Hello, World! program in rust:

On an empty folder create a file named: main.rs and add the following:

fn main() {
    println!("Hello, world!");
}
Enter fullscreen mode Exit fullscreen mode

Save the file and compile the code using:

rustc main.rs
Enter fullscreen mode Exit fullscreen mode

Run the simple program:

./main
Enter fullscreen mode Exit fullscreen mode

If Hello, world! did print, congratulations! You have successfully installed Rust

image1

Installing near-cli

To install thenear-cli simply use:

npm install -g near-cli
Enter fullscreen mode Exit fullscreen mode

More on near-cli can be found here.

Conclusion

The post takes you through installing Rust and near-cli for blockchain development.

Resources:

Top comments (0)