Dec 20, 2023
Solana Onboarding via Anchor Framework for Rust Developers
Install Rust and Cargo
- To be able to compile Rust based Solana programs, install the Rust language and Cargo (the Rust package manager) using Rustup:
Install the Solana CLI
- Install the Solana CLI tool running command
Run your localhost validator
- The Solana CLI comes with the test validator built in. This command line tool will allow you to run a full blockchain cluster on your machine.
Configure your Solana CLI to use your localhost validator for all your future terminal commands and Solana program deployment:
Install Anchor
- Anchor is a framework for Solana development. It is quite similar to hardhat in many respects.
Create a new Rust library with Anchor
- Solana programs written in Rust are libraries which are compiled to BPF bytecode and saved in the .so format.
Initialize a new Rust library named hello_world via the Cargo command line:
Sync program_id with the anchor key and run test
Create your first Anchor program
The code for your Anchor based Solana program will live in your src/lib.rs file. Inside src/lib.rs you will be able to import your Rust crates and define your logic. Open your src/lib.rs file in your favorite editor.
Build your Anchor program
Inside a terminal window, you can build your Solana Rust program by running in the root of your project (i.e. the directory with your Cargo.toml file):