Solana CLI Basics
This section provides some common commands and examples to help you get you started using the Solana CLI.
Solana config
Your Solana config specifies the following variables:
- Config file: The path to your config file
- RPC URL & Websocket URL: The Solana cluster to which the CLI makes requests
- Keypair path:
The path to the default Solana wallet (keypair) used to pay transaction fees and deploy programs.
By default, this file is stored at
~/.config/solana/id.json.
To see your current configuration settings, enter the follow command in your terminal.
$solana config get
A successful command will return output similar to the following:
Config File: /Users/test/.config/solana/cli/config.ymlRPC URL: https://api.mainnet-beta.solana.comWebSocket URL: wss://api.mainnet-beta.solana.com/ (computed)Keypair Path: /Users/test/.config/solana/id.jsonCommitment: confirmed
You can change the Solana CLI cluster with the following commands:
$solana config set --url mainnet-beta$solana config set --url devnet$solana config set --url localhost$solana config set --url testnet
Create a wallet
Before you can send a transactions using the Solana CLI, you need a Solana wallet funded with SOL.
To generate a keypair at the default keypair path, run the following command:
$solana-keygen new
A successful command will return output similar to the following:
Generating a new keypairFor added security, enter a BIP39 passphraseNOTE! This passphrase improves security of the recovery seed phrase NOT thekeypair file itself, which is stored as insecure plain textBIP39 Passphrase (empty for none):Wrote new keypair to /Users/test/.config/solana/id.json===========================================================================pubkey: 8dBTPrjnkXyuQK3KDt9wrZBfizEZijmmUQXVHpFbVwGT===========================================================================Save this seed phrase and your BIP39 passphrase to recover your new keypair:cream bleak tortoise ocean nasty game gift forget fancy salon mimic amazing===========================================================================
This command will not override an existing account at the default location,
unless you use the --force flag.
To view your wallet's address (public key), run:
$solana address
Airdrop SOL
Request an airdrop of SOL to your wallet to pay for transactions and program deployments.
- Set your cluster to Devnet:
$solana config set -ud
- Request an airdrop of Devnet SOL:
$solana airdrop 2
Devnet airdrops limit requests to 5 SOL per request. If you hit rate limits or encounter errors, try using the Web Faucet instead.
To check your wallet's SOL balance, run the following command:
$solana balance
Run local validator
The Solana CLI includes a built-in test validator for local development.
Open a new terminal and update your CLI to use localhost:
$solana config set -ul
Run the following command to start a local validator:
$solana-test-validator
Is this page helpful?