Learn Solana CLI

Wallet types

  • file
  • paper
  • hardware

Create wallet

create wallet (key-pair)

1
2
3
4
// file wallet
solana-keygen new --outfile YOUR-PRIVATE-KEY-FILE-PATH
// paper wallet
solana-keygen new --no-outfile

the public key will display on the terminal
if you didn’t save the pubkey, it’s fine.
we can get the pubkey from private-key

1
solana-keygen pubkey YOUR-PRIVATE-KEY-FILE-PATH

Verify key-pair

1
solana-keygen verify PUBKEY PRIVATE-KEY-FILE-PATH

Interact with wallet

  • pubkey aka. address aka. wallet address

config

1
solana config get

set URL to dev-net for developing

1
solana config set --url https://api.devnet.solana.com

send 1 SOL to address

1
solana airdrop 1 PUBKEY

get balance of address

1
solana balance PUBKEY

transfer

  • from
  • to
  • amount
  • fee-payer
1
2
3
solana transfer --from <KEYPAIR> \
<RECIPIENT_ACCOUNT_ADDRESS> <AMOUNT> \
--fee-payer <KEYPAIR>

Stake

create stake account

1
2
3
4
5
6
7
// first create a keypair for account address
solana-keygen new --no-passphrase -o stake-account.json

// then create account
solana create-stake-account --from <KEYPAIR> stake-account.json <AMOUNT> \
--stake-authority <KEYPAIR> --withdraw-authority <KEYPAIR> \
--fee-payer <KEYPAIR>

get account

1
solana stake-account <STAKE_ACCOUNT_ADDRESS>

update account auth

1
2
3
solana stake-authorize <STAKE_ACCOUNT_ADDRESS> \
--stake-authority <KEYPAIR> --new-stake-authority <PUBKEY> \
--fee-payer <KEYPAIR>

Delegate Stake (質押)

list available validators

1
solana validators

delegate

1
2
solana delegate-stake --stake-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> <VOTE_ACCOUNT_ADDRESS> \
--fee-payer <KEYPAIR>

deactive

1
2
solana deactivate-stake --stake-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> \
--fee-payer <KEYPAIR>

withdraw sol

only work when the stake-account deactived

1
2
solana withdraw-stake --withdraw-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> <RECIPIENT_ADDRESS> <AMOUNT> \
--fee-payer <KEYPAIR>

split

You may want to delegate stake to additional validators while your existing stake is not eligible for withdrawal. It might not be eligible because it is currently staked, cooling down, or locked up. To transfer tokens from an existing stake account to a new one

1
2
solana split-stake --stake-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> <NEW_STAKE_ACCOUNT_KEYPAIR> <AMOUNT> \
--fee-payer <KEYPAIR>

Reference