Ensure the Solana CLI is installed and configured:
solana --version
If not installed, follow the official guide.
Install Rust via rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Install the Anchor CLI:
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
Install the latest version of the CLI using avm
:
avm install latest
Verify the installation.
anchor --version
Ensure Node.js and npm are installed for JavaScript/TypeScript bindings.
Start a local Solana test validator with custom programs and accounts:
solana-test-validator -r \
--bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s metadata.so \
--account 7FTdQdMqkk5Xc2oFsYR88BuJt2yyCPReTpqr3viH6b6C nft.json \
--account 4tSgNWeqtgp2kwRgjTqgpenP4wxfPaVCvganMR2gnd8W metadata.json
-r
: Resets the validator's state on startup.--bpf-program
: Deploys a program to the local validator.--account
: Loads an account with pre-configured data.
Set the cluster to localnet
:
solana config set --url localhost
Navigate to your Anchor project directory and build the program:
anchor build
Ensure your wallet has SOL for deployment. Request an airdrop if necessary:
solana airdrop 4
Deploy the program to Localnet:
anchor deploy
Switch to the Solana Devnet cluster:
solana config set --url devnet
Ensure your wallet has SOL for deployment. Request an airdrop if necessary:
solana airdrop 4
Run the build command to compile the program:
anchor build
Deploy the program to Devnet:
anchor deploy
After deploying to Localnet, you can test the program with:
anchor test --skip-local-validator
For Devnet execute without --skip-local-validator
flag
anchor test
View logs for transactions:
solana logs
Ensure the correct program ID is set in your Anchor.toml
and matches the deployed program.
Request more SOL for deployment:
solana airdrop 3
Ensure the program is correctly built and deployed to the target cluster.