🚀Mastering Solana CLI: From Basics to Advanced

Sachin BorseSachin Borse
4 min read

The Solana blockchain has quickly gained popularity for its scalability and low transaction costs. For developers and validators, the Solana CLI is the go-to tool for interacting with the blockchain. Whether you're setting up a wallet, deploying programs, or running a validator, this guide will cover everything from basic to advanced Solana CLI commands, all with explanations and example outputs.


Getting Started: Basic Solana CLI Commands

Check Current Solana Configuration

solana config get

Output:

Config File: /home/user/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
Keypair Path: /home/user/.config/solana/id.json

This shows the current network, RPC URL, and your wallet's configuration.

Set Solana Network to Devnet

solana config set --url devnet

Output:

Config File: /home/user/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com

You can switch between networks (Devnet, Testnet, Mainnet) with this command.

Run a Local Solana Blockchain

solana-test-validator

Output:

Ledger location: test-ledger
Log: test-ledger/validator.log

This starts a local test blockchain on your machine.

Point CLI to Local Network

solana config set --url http://127.0.0.1:8899

Output:

RPC URL: http://127.0.0.1:8899

Switch the configuration to interact with the locally running blockchain.


Working with Wallets

Create a New Wallet

solana-keygen new

Output:

Wrote new keypair to /home/user/.config/solana/id.json

Creates a new wallet on your local machine.

View Wallet Public Key

solana address

Output:

Your public key: 3FbqZx...EJXb

This is your wallet's public key (address) for receiving SOL.

Check Wallet Balance

solana balance

Output:

1.000000000 SOL

Displays your current balance in SOL.

Airdrop Test Tokens

solana airdrop 1

Output:

Requesting airdrop of 1 SOL

Airdrops SOL to your wallet, useful for testing on Devnet.


Advanced Commands for Validators

Run a Full Validator Node

solana-validator --identity /path/to/validator-keypair.json --vote-account /path/to/vote-account-keypair.json --entrypoint entrypoint.mainnet-beta.solana.com:8001

This command starts a validator node connected to Mainnet Beta.

Set Validator Identity

solana-validator --identity /path/to/identity-keypair.json

Sets the identity keypair for the validator node.

Configure RPC Port for Validator

solana-validator --rpc-port 8899

This configures the RPC port for client connections to the validator node.


Cluster Information Commands

Get Cluster Version

solana cluster-version

Output:

1.7.10

Shows the current version of the Solana cluster you're connected to.

List Cluster Nodes

solana gossip

Output:

Node: 3FbqZx...EJXb  |  RPC: 127.0.0.1:8899  |  Version: 1.7.10

Lists all the nodes in the cluster, including their public keys and versions.

Get Leader Schedule

solana leader-schedule

Output:

Slot   Leader
123456 3FbqZx...EJXb
123457 4GhDpz...FgTh

Displays the leader schedule for the current epoch, which validators are producing blocks.


Keypair Management Utilities

Verify a Keypair

solana-keygen verify <pubkey> <keypair.json>

Output:

Verified: true

Checks if a public key matches the provided keypair.

Generate a Keypair from a Seed

solana-keygen new --no-outfile --from-bip39-phrase

Generates a keypair using a BIP39 seed phrase, useful for key recovery.

Recover a Keypair with a Passphrase

solana-keygen recover --force --outfile /path/to/keypair.json

Recovers a keypair using a seed phrase and passphrase, writing it to a file.


Fee and Rent Management

Check Current Transaction Fees

solana fees

Output:

Lamports per signature: 5000

Displays the current network transaction fees in lamports.

Calculate Rent Exemption

solana rent <data_length>

Output:

Rent exempt amount: 12345678 lamports

Calculates the minimum balance required for an account to be rent-exempt based on its data size.


Logs and Monitoring

Stream Real-Time Transaction Logs

solana logs

Streams logs from the network in real-time, useful for debugging transactions.

Ping a Public Key

solana ping <pubkey>

Measures network latency to the specified public key by sending test transactions.


Miscellaneous Commands

Transfer SOL

solana transfer <recipient_pubkey> <amount>

Output:

Transaction Signature: 5E9zp...He19

Transfers SOL from your wallet to another account.

Simulate a Transaction

solana simulate <transaction.json>

Simulates a transaction without broadcasting it, useful for testing.

Get Inflation Rate

solana inflation-rate

Output:

Epoch Inflation Rate: 7.5%

Displays the current inflation rate on the network.

Fetch Inflation Rewards

solana inflation-reward --epoch <epoch_number> <stake_account_pubkey>

Retrieves inflation rewards for a stake account during a specific epoch.


Conclusion

The Solana CLI offers a wide range of commands for managing wallets, interacting with the blockchain, deploying programs, running validators, and more. Whether you're just getting started or operating as a validator, mastering these commands will help you make the most out of Solana's powerful ecosystem.

With these commands, you’re now equipped to manage your Solana accounts, deploy smart contracts, and even run a validator. If you have any questions or want more tutorials, feel free to leave a comment!

0
Subscribe to my newsletter

Read articles from Sachin Borse directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sachin Borse
Sachin Borse