CLI Command Reference
| Task | Command |
|---|---|
| Build program | cargo build-sbf |
| Deploy new program | solana program deploy <path_to_program.so> |
| Update existing program | solana program deploy <path_to_program.so> (same as deploy) |
| Show program info | solana program show <program-id> |
| Transfer program authority | solana program set-upgrade-authority <program-id> --new-upgrade-authority <path_to_keypair> |
| Make program immutable | solana program set-upgrade-authority <program-id> --final |
| Close program | solana program close <program-id> --bypass-warning |
| Check wallet balance | solana balance |
| Request airdrop (localhost) | solana airdrop 2 (on devnet, use faucet.solana.com) |
Key Concepts
Before diving in, let’s clarify some terminology:- Program ID: The onchain address of your program. Users interact with your program by referencing the Program ID.
- Program Account: The onchain account that stores your program’s metadata. The program account’s address is the Program ID. The program account also stores the address of the ProgramData Account.
- ProgramData Account: The onchain account that stores your program’s deployed executable code.
- Program Authority: The account that has permission to update or close the program. By default, this is your CLI wallet.
Prerequisites
1
Install the Solana CLI
First, install the Solana CLI.
2
Set Up Wallet
After installation, create a local keypair wallet. The address of this wallet is
set as the default program authority when deploying programs:This creates a keypair at
Terminal
~/.config/solana/id.json by default.3
Configure Cluster
Choose which Solana cluster to deploy to. Use the Switch between clusters as needed:
solana config get command to
check your current configuration:Terminal
Output
Terminal
4
Fund Wallet
You’ll need SOL to pay for program deployments. The amount depends on your
program size.On devnet, get free devnet SOL from the
Solana Faucet: paste the address that
Check your wallet balance:
solana address prints and request SOL. The devnet RPC faucet is closed, so
solana airdrop works only on a local validator. On localhost, fund your
wallet with the solana airdrop command:Terminal
Output
Terminal
Output
Basic Operations
Build Program
To build a program, use thecargo build-sbf command:
Terminal
1
Example Program
Here is a minimal Solana program that prints “Hello, Solana!” to the program
logs.
2
Build Output
Build your program using the This creates two important files in
cargo build-sbf command:Terminal
target/deploy/:hello_world-keypair.json: A keypair file whose public key will be used as your Program IDhello_world.so: The compiled program executable
Check Program Size and Cost
Deploying a program requires SOL to be allocated to the program account based on the size of the program. Larger programs cost more SOL to deploy. Check your program’s size:Terminal
Output
Terminal
Output
You’ll need slightly more SOL than shown to cover deployment transaction fees.
Deploy Program
Use thesolana program deploy command to deploy your program:
Terminal
Output
To deploy with a specific Program ID (instead of the auto-generated one), use:You can generate new keypairs using the
Terminal
solana-keygen command:Terminal
Update Program
Update your program using the samesolana program deploy command:
- Make changes to your program code
- Rebuild your program:
cargo build-sbf - Deploy the update:
Terminal
Output
If your updated program requires more space (bytes) than currently allocated,
the deployment will automatically extend the program account. This happens when
your new program is larger than the previous version. The program account needs
additional bytes to store the new program. The CLI will calculate the required
SOL and deduct it from your wallet automatically.You can also manually extend a program to allocate more bytes. The minimum
extension is 10,240 bytes (10 KiB), unless you are extending to the maximum
program size
(SIMD-0431):
Terminal
Output
Program Management
Once your program is deployed, there are several common commands to manage the program account.View Program Metadata
To check your program metadata, use thesolana program show command:
Terminal
Program IdThe Program ID is the onchain address of your program account. Users and other
programs invoke your program by referencing this ID in their transactions.OwnerThe Owner identifies which loader was used to deploy this program. For most
programs, this will be the BPF Upgradeable Loader.ProgramData AddressThe ProgramData Address points to the separate account that stores your
program’s executable code.AuthorityThe Authority is the account that has permission to upgrade or close this
program. Only the authority can deploy updates or close the program to reclaim
the program’s allocated SOL.Last Deployed In SlotThe Last Deployed In Slot indicates when this program was last updated.Data LengthThe Data Length shows the total bytes allocated to this program. This space can
accommodate future updates that may be larger than the current program size.BalanceThe Balance displays the SOL allocated to the program account to store its data.Transfer Program Authority
To transfer the program authority to a different account, use thesolana program set-upgrade-authority command:
Terminal
After transferring the program authority, you can no longer update the program
unless you have access to the new authority keypair.
Make Your Program Immutable
To make your program immutable, use thesolana program set-upgrade-authority
command with the --final flag to remove the program authority:
Terminal
Output
Once a program is immutable, it can never be updated or closed.
Close Your Program
To close your program and reclaim the SOL allocated to the program account, use thesolana program close command:
Terminal
Output
Once closed, the Program ID can not be reused. You cannot deploy a new program
to the same address.
Utility Commands
List All Programs
View all programs where your current wallet is the authority:Terminal
Download a Deployed Program
To download a deployed program, use thesolana program dump command:
Terminal
Output
Advanced Options
Deployment Flags
When the Solana network is congested, use these flags to help with program deployment. Example Usage:Terminal
--with-compute-unit-price: Set priority fee in micro-lamports (1 micro-lamport = 0.000001 lamport) per compute unit. Check Helius Priority Fee API for current rates. A priority fee is an additional fee that is paid to the current leader to prioritize your transaction.--max-sign-attempts: Number of times to retry with a new blockhash if transactions expire. (Default: 5)--use-rpc: Send transactions to the configured RPC. This flag requires a stake-weighted RPC connection from providers such as Triton or Helius.