This project demonstrates how to build programs on the Solana blockchain with cargo-make.
The project comprises of:
- An on-chain hello world program
- A client that can send a "hello" to an account and get back the number of times "hello" has been sent
- Quick Start
- Writing the client in Rust
- Pointing to a public Solana cluster
- Learn about Solana
- Learn about the on-chain program
The following dependencies are required to build and run this example, depending on your OS, they may already be installed:
- Install cargo-make 0.35.13 or later with
cargo install cargo-make
- Install Rust v1.62.0 or later from https://rustup.rs/
- Install Solana v1.8.14 or later from https://docs.solana.com/cli/install-solana-cli-tools
If this is your first time using Rust, these Installation Notes might be helpful.
If you're on Windows, it is recommended to use WSL to run these commands
- Set CLI config url to localhost cluster
solana config set --url localhost
- Create CLI Keypair
If this is your first time using the Solana CLI, you will need to generate a new keypair:
solana-keygen new
This example connects to a local Solana cluster by default.
Start a local Solana cluster:
solana-test-validator
Note: You may need to do some system tuning (and restart your computer) to get the validator to run
Listen to transaction logs:
solana logs
There is both a Rust version of the on-chain program, whichever is built last will be the one used when running the example.
cargo make build
cargo make deploy
To customize the example, make changes to the files under /src
. If you change
any files you will need to
rebuild the on-chain program and redeploy the program.
Solana client program can be written in any language. For an example client written in Rust and an accompanying write up see this repo.
Solana maintains three public clusters:
devnet
- Development cluster with airdrops enabledtestnet
- Tour De Sol test cluster without airdrops enabledmainnet-beta
- Main cluster
Use the Solana CLI to configure which cluster to connect to.
To point to devnet
:
solana config set --url devnet
To point back to the local cluster:
solana config set --url localhost
More information about how Solana works is available in the Solana documentation and all the source code is available on github
The on-chain helloworld program is a Rust program compiled to Berkeley Packet Filter (BPF) bytecode and stored as an Executable and Linkable Format (ELF) shared object.
The program is written using:
To learn more about Solana programming model refer to the Programming Model Overview.
To learn more about developing programs on Solana refer to the On-Chain Programs Overview