Quick Start
The following dependencies are required to build and run this example:
- Install Rust v1.60.0 or later from rustup.rs
- Install Solana v1.10.8 or later from docs.solana.com/cli/install-solana-cli-tools
If this is your first time using Rust, see the Installation Notes.
Configure CLI
Set CLI config url to localhost cluster:
solana config set --url localhost
Create CLI Keypair (if first time):
solana-keygen new
Start Local Solana Cluster
solana-test-validator
For a clean slate after trials:
solana-test-validator --reset
Note: You may need to do some system tuning to get the validator to run.
View on-chain program logs in a separate terminal:
solana logs
Note: Use
msg!macro for logging inside the on-chain program.
Build the On-Chain Program
cd program
cargo build-bpf
Deploy the On-Chain Program Locally
solana program deploy target/deploy/program.so
Run the Rust Client
cargo run
Expected Output
Connecting to cluster...http://localhost:8899
Connection to cluster established
Cluster node solana version 1.10.5
Counter account B6rWFbQ4pmb4pvcZstFCjLXffZSaqqn6c8fdXzpK3WSX already exists. Owner program: HGsPi7r4MEeUSC74vzx9qCqJvuuBb3AcjNc5MrtEjCGu
Binary address 8cRrhLjJ7sSbSa1kuaShq2Ywu1otyRhkNwTQ3E1Bqr4T
Fee for message 5000
Counter value 1
Values will differ!
Not seeing the expected output? Ensure you’ve started the local cluster, built the on-chain program, and deployed it.
Deploy to Devnet
solana config set --url d
solana program deploy target/deploy/program.so
Deploy to Testnet
solana config set -ut
solana program deploy target/deploy/program.so
Note: You may not have required SOL balance. Airdrop SOL into your account:
solana balance
solana airdrop 1