In this part of the Solana Documentation, we explore how to interact with a Solana Cluster via the command line. For this you will need to install the Solana Command Line Tools on Linux, MacOS or Windows.

In this tutorial we will connect to a cluster, create a wallet and explore some of the Solana command line options SOL Wallet creation, airdropping SOL, transferring SOL, checking your wallet balance and confirming transactions.

Missed something? Check out the rest of the Inside the Solana Docs blog post series:

Installing Solana Command Line Tools

You need Linux, MacOS or Windows to setup the CLI tools.

curl -sSf https://raw.githubusercontent.com/solana-labs/solana/v1.1.10/install/solana-install-init.sh | sh -s - v1.1.10
Linux (195 mb)
MacOS (62 mb)
Windows (32 mb)

You can also download the binaries manually if the above script doesn’t work.

Halfway through writing this article, Solana updated from v1.1.9, to v1.1.10, to v1.1.12 ! Stay tuned for the latest updates at Solana Releases. They also adding instructions for installing Solana on Windows to their Docs. It goes to show you how FAST the Solana Development teams are pushing out code.

Solana Releases actually added assets for Windows back on 24th March 2020
Windows command-line binaries are now available: solanasolana-keygensolana-install

MAC TIP: Your computer may complain that “Solana” is not trusted. To manually trust it, just open “Preferences > Security & Privacy” to “Allow” Solana. From there within Terminal you can see all the Solana command line tools!

My-air:Solana$ solana
solana-cli 1.1.10
Blockchain, Rebuilt for Scale

USAGE:
    solana [FLAGS] [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help                           Prints help information
        --skip-seed-phrase-validation    Skip validation of seed phrases. Use this if your phrase does not use the BIP39
                                         official English word list
    -V, --version                        Prints version information
    -v, --verbose                        Show additional information

OPTIONS:
    -C, --config <FILEPATH>         Configuration file to use [default: /Users/solana/.config/solana/cli/config.yml]
    -u, --url <URL>                 JSON RPC URL for the solana cluster
    -k, --keypair <KEYPAIR>         Filepath or URL to a keypair
        --output <output_format>    Return information in specified output format. Supports: json, json-compact
                                    [possible values: json, json-compact]
        --ws <URL>                  WebSocket URL for the solana cluster

SUBCOMMANDS:
    account                             Show the contents of an account
    address                             Get your public key
    airdrop                             Request lamports
    authorize-nonce-account             Assign account authority to a new entity
    balance                             Get your balance
    block-production                    Show information about block production
    block-time                          Get estimated production time of a block
    cancel                              Cancel a transfer
    catchup                             Wait for a validator to catch up to the cluster
    claim-storage-reward                Redeem storage reward credits
    cluster-date                        Get current cluster date, computed from genesis creation time and network time
    cluster-version                     Get the version of the cluster entrypoint
    config                              Solana command-line tool configuration settings
    confirm                             Confirm transaction by signature
    create-address-with-seed            Generate a derived account address with a seed
    create-archiver-storage-account     Create an archiver storage account
    create-nonce-account                Create a nonce account
    create-stake-account                Create a stake account
    create-validator-storage-account    Create a validator storage account
    create-vote-account                 Create a vote account
    deactivate-stake                    Deactivate the delegated stake from the stake account
    decode-transaction                  Decode a base-85 binary transaction
    delegate-stake                      Delegate stake to a vote account
    deploy                              Deploy a program
    epoch                               Get current epoch
    epoch-info                          Get information about the current epoch
    fees                                Display current cluster fees
    genesis-hash                        Get the genesis hash
    gossip                              Show the current gossip network nodes
    help                                Prints this message or the help of the given subcommand(s)
    leader-schedule                     Display leader schedule
    live-slots                          Show information about the current slot progression
    new-nonce                           Generate a new nonce, rendering the existing nonce useless
    nonce                               Get the current nonce value
    nonce-account                       Show the contents of a nonce account
    pay                                 Send a payment
    ping                                Submit transactions sequentially
    resolve-signer                      Checks that a signer is valid, and returns its specific path; useful for
                                        signers that may be specified generally, eg. usb://ledger
    send-signature                      Send a signature to authorize a transfer
    send-timestamp                      Send a timestamp to unlock a transfer
    slot                                Get current slot
    split-stake                         Duplicate a stake account, splitting the tokens between the two
    stake-account                       Show the contents of a stake account
    stake-authorize                     Authorize a new signing keypair for the given stake account
    stake-history                       Show the stake history
    stake-set-lockup                    Set Lockup for the stake account
    stakes                              Show stake account information
    storage-account                     Show the contents of a storage account
    total-supply                        Get total number of SOL
    transaction-count                   Get current transaction count
    transaction-history                 Show historical transactions affecting the given address, ordered based on
                                        the slot in which they were confirmed in from lowest to highest slot
    transfer                            Transfer funds between system accounts
    validator-info                      Publish/get Validator info on Solana
    validators                          Show summary information about the current validators
    vote-account                        Show the contents of a vote account
    vote-authorize-voter                Authorize a new vote signing keypair for the given vote account
    vote-authorize-withdrawer           Authorize a new withdraw signing keypair for the given vote account
    vote-update-validator               Update the vote account's validator identity
    withdraw-from-nonce-account         Withdraw SOL from the nonce account
    withdraw-from-vote-account          Withdraw lamports from a vote account into a specified account
    withdraw-stake                      Withdraw the unstaked SOL from the stake account 

Let’s target the Solana DevNet Cluster:

C:\Users\SOLdier>solana config set --url https://devnet.solana.com
Config File: C:\Users\SOLdier\.config\solana\cli\config.yml
RPC URL: https://devnet.solana.com
WebSocket URL: wss://devnet.solana.com/ (computed)
Keypair Path: C:\Users\SOLdier\.config\solana\id.json

C:\Users\SOLdier\Solana>solana config get
Config File: C:\Users\SOLdier\.config\solana\cli\config.yml
RPC URL: https://devnet.solana.com
WebSocket URL: wss://devnet.solana.com/ (computed)
Keypair Path: C:\Users\SOLdier\.config\solana\id.json

Now we need to make sure the local Solana install matches the Solana network cluster version:

C:\Users\SOLdier\Solana>solana --version
solana-cli 1.1.12

C:\Users\SOLdier\Solana>solana cluster-version
1.1.12 b9a80152

Link a Solana Wallet to Run CLI Commands

In order to send or receive tokens and stake in a cluster, you will need to link a wallet. If you would like more information on the different types of wallets, check out our Solana Wallet Guide. For this example, we will be creating one of the most insecure wallets, the File System Wallet.

To create a File System Wallet we will need to run the solana-keygen command.

my-air:Solana$ solana-keygen
Killed: 9

If you running this in MacOS, you will need to allow the command via System Preferences > Security & Privacy > Allow:

You can now test out you can run the command by executing “solana-keygen –help”

my-air:Solana$ solana-keygen --help
solana-keygen 1.1.10
Solana key generation utility

USAGE:
    solana-keygen [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -C, --config <FILEPATH>    Configuration file to use [default: /Users/johnny/.config/solana/cli/config.yml]

SUBCOMMANDS:
    grind      Grind for vanity keypairs
    help       Prints this message or the help of the given subcommand(s)
    new        Generate new keypair file from a passphrase and random seed phrase
    pubkey     Display the pubkey from a keypair file
    recover    Recover keypair from seed phrase and passphrase
    verify     Verify a keypair can sign and verify a message.

Let’s build File System Wallet and generate a key pair (Solana Docs):

mkdir ~/my-solana-wallet
solana-keygen new --outfile ~/my-solana-wallet-devnet/my-keypair.json

Generating a new keypair
For added security, enter a passphrase (empty for no passphrase):
Enter same passphrase again:
Wrote new keypair to ~/my-solana-wallet-devnet/my-keypair.json
=============================================================================
pubkey: 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK 
=============================================================================
Save this seed phrase to recover your new keypair:
this will be twelve random random words like weather and blast
=============================================================================

You can then verify your Public Wallet Address against your Keypair file:

solana-keygen verify 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK ~/my-solana-wallet-devnet/my-keypair.json
Verification for public key: 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK: Success

Let’s AirDrop 1000 SOL on DevNet (TestNet)

Now you can do some cool stuff and see how quick Solana is. We will run a command to check our new account has zero balance. As we are on the test network, we can airdrop ourselves some SOL! The commands we will use are as follows:

  • solana balance <ACCOUNT_ADDRESS> –url https://devnet.solana.com
  • solana airdrop 1000 <RECIPIENT_ACCOUNT_ADDRESS> –url https://devnet.solana.com
C:\Users\SOLdier\Solana>solana balance 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK --url https://devnet.solana.com
0 SOL

C:\Users\SOLdier\Solana>solana airdrop 1000 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK --url https://devnet.solana.com
Requesting airdrop of 1000 SOL from 34.82.57.86:9900
1000 SOL

C:\Users\SOLdier\Solana>solana balance 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK --url https://devnet.solana.com
1000 SOL

Now I’m going to make another wallet so I can do a SOL transfer:

C:\Users\SOLdier\Solana>solana-keygen new --outfile ~/my-solana-wallet-devnet2/my-keypair.json
Generating a new keypair
For added security, enter a passphrase (empty for no passphrase):
Enter same passphrase again:
Wrote new keypair to ~/my-solana-wallet-devnet2/my-keypair.json
================================================================================
pubkey: 45Mfukyu1XFc56Fk5yUDcbkrZY49prsgVR4eCJpd3DtW
================================================================================

Then we will transfer some sweet SOL from the first account to the second account. The first account (3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK) has a balance of 1000 SOL that we airdropped before. The second account (45Mfukyu1XFc56Fk5yUDcbkrZY49prsgVR4eCJpd3DtW) has a balance of 0 SOL.

The commands wee will use are the following, where KEYPAIR is the file path for your first wallet, RECIPIENT is the public key of your second wallet and AMOUNT is how many SOL:

  • solana transfer –from <KEYPAIR> <RECIPIENT_ACCOUNT_ADDRESS> <AMOUNT> –url https://devnet.solana.com –fee-payer <KEYPAIR>
  • solana balance <ACCOUNT_ADDRESS> –url https://devnet.solana.com
C:\Users\SOLdier\Solana>solana transfer --from ~/my-solana-wallet-devnet/my-keypair.json 45Mfukyu1XFc56Fk5yUDcbkrZY49prsgVR4eCJpd3DtW 10 --url https://devnet.solana.com --fee-payer ~/my-solana-wallet-devnet/my-keypair.json

Signature: 3gAhpt1qk9bXE7t1vusf4cX13LEiGcwrM6amgoWtMATPf95NwGXm3kYrmj4EFPQUtQL1AvePfXfN5GHdZSSspLW

C:\Users\SOLdier\Solana>solana balance 3Fj7USbqwiqVMGgL9v46kgV3eQsKYHtKPtHtJPHF6fxK --url https://devnet.solana.com
989.999995 SOL

C:\Users\SOLdier\Solana>solana balance 45Mfukyu1XFc56Fk5yUDcbkrZY49prsgVR4eCJpd3DtW --url https://devnet.solana.com
10 SOL

Above we have confirmed that the SOL transferred from one wallet to another. However, you may have noticed the blockchain confirmations counting up to 32 confirmations after you ran the command. We can also confirm the transactions was verified by the blockchain:

C:\Users\SOLdier\Solana>solana confirm 3gAhpt1qk9bXE7t1vusf4cX13LEiGcwrM6amgoWtMATPf95NwGXm3kYrmj4EFPQUtQL1AvePfXfN5GHdZSSspLW
Confirmed

There you have it! Today we successfully installed Solana Command Line Tools across Linux, MacOS and Windows! We also chose the DevNet Solana Network, created a Wallet, Airdropped some SOL, then transferred it to another Wallet !

You are Now a Solana Command Line Guru!

In the next topic, we will get into how to Stake your SOL to a Validator node and get some SOL rewards.

Stay Tuned and please share us on Twitter!