Staking SOL Natively Using Solana CLI
Last updated
Last updated
In this lesson, we'll learn how to stake SOL tokens natively using the Solana Command Line Interface (CLI). We'll cover the process from installing the Solana CLI to delegating and undelegate stake, including some advanced operations like splitting and merging stake accounts.
Before we begin, you'll need to choose an environment to work in:
For Windows users: You have two options:
Install wsl for Windows and use the Solana CLI within it.
Install Solana directly on wsl
For this tutorial, we recommend using wsl as it provides a Unix-like environment, making the commands more consistent across different operating systems.
For macOS and Linux users: You can use the terminal directly.
Let's start by installing the Solana CLI. The process varies depending on your operating system.
For Windows users, we recommend using WSL (Windows Subsystem for Linux) to install Solana CLI. This allows you to run a full-fledged Linux environment on Windows, making the process more convenient and compatible with Unix-like commands.
Step 1: Installing WSL
Open PowerShell as an administrator.
Run the following command to install WSL:
This command will install WSL and download a Linux distribution (such as Ubuntu).
After the installation is complete, restart your computer.
Step 2: Launching the Ubuntu Terminal
After restarting, open the Start Menu and search for the Ubuntu application (or any other installed Linux distribution).
Launch the Ubuntu terminal, which is now available through WSL.
Step 3: Installing Solana CLI
In the opened Ubuntu terminal, run the following command to install Solana CLI:
Once the command is executed, Solana CLI will be installed, and you will be able to use it within the WSL environment.
Note: WSL provides a complete Linux environment, simplifying interaction with Solana CLI and avoiding potential issues with architecture or compatibility when using Windows.
Open your terminal and run:
After installation, close and reopen your terminal or Git Bash window.
Verify the installation by running:
Step 2: Connecting to the Test Cluster
For this tutorial, we'll use the Devnet test cluster. Set your CLI to connect to Devnet:
Verify your connection:
Generate a new keypair in corrent directory:
This command creates a new Solana keypair and saves it to the file my-wallet.json
in the default Solana config directory. Let's break down the command:
solana-keygen
: This is the Solana tool for generating keypairs.
new
: This subcommand tells solana-keygen
to create a new keypair.
-o
: This option specifies the output file for the keypair.
When you run solana-keygen new
, you're presented with a prompt that says:
This prompt is asking you if you want to add an extra layer of security to your Solana wallet. Let's break down what this means:
BIP39 Passphrase: This is an optional feature that adds an additional word or phrase to your seed phrase. It's sometimes called a "25th word" because it's used in addition to the standard 24-word seed phrase.
Enhanced Security: If you choose to enter a passphrase, it will make your seed phrase more secure. This means that even if someone gets access to your 24-word seed phrase, they won't be able to access your wallet without also knowing this additional passphrase.
Important Note: The passphrase enhances the security of your recovery seed phrase, not the keypair file. The keypair file is still stored as plain text and is not encrypted by this passphrase.
Optional: You don't have to enter a passphrase if you don't want to. You can simply press Enter to skip this step.
Caution: If you do decide to use a passphrase, it's crucial that you remember it. If you forget your passphrase, you won't be able to recover your wallet, even if you have the 24-word seed phrase.
Remember, while adding a passphrase can increase security, it also increases the risk of permanently losing access to your wallet if you forget the passphrase. Choose carefully based on your personal security needs and your ability to securely store and remember the passphrase.
Get your public key:
Here, we're using the -k
option to specify the keypair file we just created. This option will be used in many subsequent commands to indicate which keypair should be used for the operation.
Request an airdrop of 1 SOL:
Again, we use -k
to specify our keypair file. This ensures the airdropped SOL goes to the correct address.
Verify your balance:
To create a stake account, we'll first generate a new keypair for it, then use that to create the actual stake account. Here's the process:
First, generate a new keypair for the stake account:
This command creates a new keypair and saves it to stake-account.json
in your current directory. The -o
option specifies the output file.
Now, let's create a stake account with 2 SOL:
Let's break down this command:
solana create-stake-account
: This is the command to create a new stake account.
-k ~/.config/solana/my-wallet.json
: This specifies the keypair file for your main wallet, which will fund the new stake account. The -k
option is used to point to your keypair file.
stake-account.json
: This is the keypair file for the new stake account that we just created.
0.9
: This is the amount of SOL to transfer to the new stake account.
This command will create a new stake account, transfer 0.9 SOL to it from your main wallet, and set your main wallet as both the stake and withdraw authority for the new account.
Before we proceed with setting authorities, it's crucial to understand what stake and withdraw authorities are, and how they differ from staking through a wallet like Phantom.
In Solana's staking model, there are two types of authorities associated with a stake account:
Stake Authority: This authority has the power to delegate stake, deactivate stake, and split stake accounts. It controls the staking operations of the account.
Withdraw Authority: This authority has the power to withdraw funds from the stake account and change both the stake and withdraw authorities.
These authorities are represented by public-private key pairs. By default, when you create a stake account using the CLI, both authorities are set to the keypair you used to create the account (in our case, my-wallet.json
).
When you stake through a wallet like Phantom, the process is simplified for user convenience. The wallet software typically handles both the stake and withdraw authorities using your wallet's keypair. This means:
You don't have to manage separate keys for different authorities.
All staking operations are performed through the wallet interface.
The wallet can delegate, undelegate, and withdraw rewards using a single set of keys.
In contrast, when using the CLI, you have more granular control. You can set different keypairs for stake and withdraw authorities, allowing for more complex security setups or delegation of responsibilities.
If you want to set different authorities, you can use the solana stake-authorize
command. Here's how to do it on both Unix-based systems (macOS, Linux) and Windows:
For Unix-based systems (using Bash):
In these commands:
solana address -k stake-account.json
gets the public key of the stake account.
--stake-authority
and --withdraw-authority
specify the current authorities.
--new-stake-authority
and --new-withdraw-authority
set the new authorities. You need to replace <NEW_STAKE_AUTHORITY_PUBKEY>
and <NEW_WITHDRAW_AUTHORITY_PUBKEY>
with the actual public keys of the new authorities.
-k my-wallet.json
specifies the keypair file used to sign the transaction.
Remember, changing authorities is a significant action. Ensure you have secure backups of all keypairs and understand the implications before proceeding.
First, let's understand why we might want to split a stake account, and then we'll correct the command.
Splitting a stake account can be useful for several reasons:
Diversification: You can split your stake to delegate to multiple validators, spreading your risk and potentially increasing your rewards.
Partial Unstaking: If you want to unstake only a portion of your staked SOL, you can split the account and unstake just one part.
Gradual Staking: You can split a large stake into smaller portions to stake gradually over time.
Different Authorities: You might want to assign different stake or withdraw authorities to different portions of your stake.
Solana has a minimum stake requirement of 1 SOL per stake account.
Now, let's correct the command and explain how to properly split a stake account.
Before splitting, we need to create a new keypair for the split stake account:
Now we can use this new keypair to split the stake:
After executing this command, you'll have two stake accounts:
The original account with 1 SOL less than before.
A new account with 1 SOL.
You can verify the split by checking both accounts:
Remember, splitting a stake account doesn't change its delegation status. If the original account was delegated, the new split account will be delegated to the same validator. You can then manage these accounts separately, including delegating them to different validators if desired.
To merge the split stake accounts back together:
You can verify the split by checking both accounts:
This step involves two parts: finding a validator and then delegating your stake to them.
Since we are currently connected to the test network, we will receive a list of test validators. You can also view validator vote accounts on platforms such as StakeWiz or SolanaBeach.
To find a validator, we use the command:
This command displays a list of all active validators on the network. The output includes important information such as:
Validator identity pubkey
Vote account address
Commission (the percentage of rewards the validator takes)
Last vote
Root slot
Credits
Active stake
When choosing a validator, consider factors like commission rate, performance (credits), and total active stake. A lower commission means more rewards for you, but very low commissions might indicate a less reliable validator.
Delegating Your Stake
Once you've chosen a validator, use this command to delegate your stake:
Let's break this down:
solana delegate-stake
: This is the command to delegate your stake.
-k my-wallet.json
: This specifies the keypair file for your wallet. This should be the stake authority for the stake account.
$(solana address -k stake-account.json)
: This gets the address of your stake account.
<VOTE_ACCOUNT_ADDRESS>
: Replace this with the vote account address of the validator you chose.
This command delegates the entire balance of your stake account to the specified validator.
After delegation, your stake will go through a warm-up period before it becomes active and starts earning rewards.
After successful delegation, we received a signature: 5ZsugXEtPsjqS5r4vsxGcykbhjxr39Ehx3XDxcNnfuACR6qVcUPcDrwehKyUSpxY8KgVq4kCaeAoRv2io6ppVFrE
Since this lesson is for learning purposes, don't forget that the explorer also needs to be switched to testnet mode. The testnet is a separate network with its own list of validators and test SOL.
Pay attention to the details of this transaction. Here we can see the stake-authorize keys that we discussed in step 5.
Let's take a look at our staking account right away. Here we can see the validator to whom we delegated our staking account, as well as the Withdraw and Stake Authorities.
And here's our wallet that we called my-wallet.json. Here we can see all the actions that we signed using this account.
If you want to stop delegating your stake (perhaps to withdraw it or delegate to a different validator), you need to deactivate it first.
Use this command:
Let's break this down:
solana deactivate-stake
: This is the command to deactivate your delegated stake.
-k my-wallet.json
: Again, this specifies your keypair file, which should have stake authority.
$(solana address -k stake-account.json)
: This gets the address of your stake account.
Important Notes:
Delegation and deactivation are not instant processes due to Solana's epoch-based staking model.
You can check the status of your stake account at any time using:
Remember that while your stake is delegated or cooling down, it's still in your stake account. You haven't lost control of your funds; they're just not immediately liquid.
Congratulations! You've now learned how to perform basic and advanced staking operations using the Solana CLI. Remember, these operations were performed on the Devnet test network. When you're ready to stake on the main network, make sure to switch your CLI to the mainnet-beta cluster and use real SOL.
Always double-check your commands and addresses before executing them, especially when working with real funds on the main network.
Congratulations on completing this practical lesson on staking SOL natively using the Solana CLI! Now it's time to put your newly acquired skills to the test and earn rewards for your hard work.
We've prepared a special quest that will allow you to demonstrate your understanding of the Solana staking process using CLI. By completing this quest, you'll not only reinforce your learning but also earn points and a special badge in our Sol Invictus loyalty program.
Follow all the steps outlined in this lesson, from installing the Solana CLI to delegating your stake to a validator.
Pay special attention to the delegation process and the resulting transaction.
Locate your delegation transaction in the Solana explorer (remember to use the testnet explorer).
Copy the link to your delegation transaction - you'll need this as proof of completion.
To submit your exam and claim your rewards, please visit our Zealy quest page:
On this page, you'll find detailed instructions for submitting your proof of completion. Remember, the transaction link you provide should clearly show the delegation of your stake account to a validator on the Solana testnet.
By successfully completing this exam, you'll earn:
300 extra points in our loyalty program
A special "Exam Week 1" badge
These rewards showcase your practical skills in Solana staking via CLI and contribute to your overall standing in the Sol Invictus loyalty program.
Remember, this exam is not just about completion - it's an opportunity to gain hands-on experience with Solana's CLI and deepen your understanding of the staking process. Take your time, refer back to the lesson materials as needed, and enjoy the learning process!
Good luck, and may your stakes be ever in your favor!
If the command is not executed, because the stocks of test SOL have been depleted.
StakeWiz ()
Solana Beach ()
We can now find this transaction in the explorer:
If you encounter any issues or have questions while completing this exam, don't hesitate to ask for help in our dedicated Our community and team members are ready to assist you in succeeding.