ElagabalX
  • 👨‍🔧ElagabalX
    • Introduction
      • Our Mission and Vision
    • What is staking and who are the validators?
      • APY and Rewards
      • Performance Metrics
    • xSOL token
    • ☀️SOL Invictus Program
      • Points overview
      • STAKING
        • Native Staking
        • xSOL Liquid Staking
        • Solblaze Custom Liquid Staking (CLS)
        • VaultSol Custom Liquid Staking
        • BLZE DAO VOTES
      • ElagabalX Referral Program
      • HODLEMOD: Bonuses for Holding in Staking
    • Education Classes
      • HawkSight Exams
      • Staking SOL Natively Using Solana CLI
    • Magistratus dApp
    • For content creators
      • Brand Guidelines
    • Partnerships
    • Community and Socials
    • Legal and compiliance
Powered by GitBook
On this page
  • Introduction
  • Prerequisites
  • Step 1: Installing Solana CLI
  • Step 3: Creating a Wallet and Getting SOL
  • Step 4: Creating a Stake Account
  • Step 5: Understanding and Setting Stake and Withdraw Authorities (OPTIONAL)
  • Step 6: Splitting a Stake Account (OPTIONAL)
  • Step 7: Merging Stake Accounts
  • Step 8: Delegating to a Validator
  • Step 9: Deactivating the Delegation
  • Conclusion
  • Practical Exam: Put Your Skills to the Test
  1. ElagabalX
  2. Education Classes

Staking SOL Natively Using Solana CLI

PreviousHawkSight ExamsNextMagistratus dApp

Last updated 7 months ago

Introduction

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.

Prerequisites

Before we begin, you'll need to choose an environment to work in:

  • For Windows users: You have two options:

    1. Install wsl for Windows and use the Solana CLI within it.

    2. 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.

Step 1: Installing Solana CLI

Let's start by installing the Solana CLI. The process varies depending on your operating system.

For Windows (using WSL)

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

  1. Open PowerShell as an administrator.

  2. Run the following command to install WSL:

    wsl --install

    This command will install WSL and download a Linux distribution (such as Ubuntu).

  3. After the installation is complete, restart your computer.

Step 2: Launching the Ubuntu Terminal

  1. After restarting, open the Start Menu and search for the Ubuntu application (or any other installed Linux distribution).

  2. Launch the Ubuntu terminal, which is now available through WSL.

Step 3: Installing Solana CLI

  1. In the opened Ubuntu terminal, run the following command to install Solana CLI:

    sh -c "$(curl -sSfL https://release.solana.com/v1.18.18/install)"

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.

For macOS and Linux

Open your terminal and run:

sh -c "$(curl -sSfL https://release.solana.com/v1.18.18/install)"

After installation, close and reopen your terminal or Git Bash window.

Verify the installation by running:

solana --version

Step 2: Connecting to the Test Cluster

For this tutorial, we'll use the Devnet test cluster. Set your CLI to connect to Devnet:

solana config set --url https://api.testnet.solana.com

Verify your connection:

solana config get

Step 3: Creating a Wallet and Getting SOL

  1. Generate a new keypair in corrent directory:

solana-keygen new -o my-wallet.json

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:

CopyFor added security, enter a BIP39 passphrase
NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text

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:

  1. 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.

  2. 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.

  3. 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.

  4. Optional: You don't have to enter a passphrase if you don't want to. You can simply press Enter to skip this step.

  5. 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.

  1. Get your public key:

solana address -k my-wallet.json

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.

  1. 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.

solana airdrop 1 -k my-wallet.json

Verify your balance:

solana balance -k my-wallet.json

Step 4: Creating a Stake Account

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:

  1. First, generate a new keypair for the stake account:

solana-keygen new -o stake-account.json

This command creates a new keypair and saves it to stake-account.json in your current directory. The -o option specifies the output file.

  1. Now, let's create a stake account with 2 SOL:

solana create-stake-account -k my-wallet.json stake-account.json 2

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.

Step 5: Understanding and Setting Stake and Withdraw Authorities (OPTIONAL)

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.

What are Stake and Withdraw Authorities?

In Solana's staking model, there are two types of authorities associated with a stake account:

  1. Stake Authority: This authority has the power to delegate stake, deactivate stake, and split stake accounts. It controls the staking operations of the account.

  2. 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).

Difference from Wallet Staking (e.g., Phantom)

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:

  1. You don't have to manage separate keys for different authorities.

  2. All staking operations are performed through the wallet interface.

  3. 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.

Setting Different Authorities

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):

solana stake-authorize $(solana address -k stake-account.json) \
    --stake-authority my-wallet.json \
    --new-stake-authority <NEW_STAKE_AUTHORITY_PUBKEY> \
    -k my-wallet.json

solana stake-authorize $(solana address -k stake-account.json) \
    --withdraw-authority my-wallet.json \
    --new-withdraw-authority <NEW_WITHDRAW_AUTHORITY_PUBKEY> \
    -k my-wallet.json

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.

Step 6: Splitting a Stake Account (OPTIONAL)

First, let's understand why we might want to split a stake account, and then we'll correct the command.

Why Split a Stake Account?

Splitting a stake account can be useful for several reasons:

  1. Diversification: You can split your stake to delegate to multiple validators, spreading your risk and potentially increasing your rewards.

  2. Partial Unstaking: If you want to unstake only a portion of your staked SOL, you can split the account and unstake just one part.

  3. Gradual Staking: You can split a large stake into smaller portions to stake gradually over time.

  4. Different Authorities: You might want to assign different stake or withdraw authorities to different portions of your stake.

  5. 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:

solana-keygen new -o split-stake-account.json

Now we can use this new keypair to split the stake:

solana split-stake -k my-wallet.json \
    $(solana address -k stake-account.json) \
    split-stake-account.json 1

After executing this command, you'll have two stake accounts:

  1. The original account with 1 SOL less than before.

  2. A new account with 1 SOL.

You can verify the split by checking both accounts:

solana stake-account $(solana address -k stake-account.json)
solana stake-account $(solana address -k split-stake-account.json)

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.

Step 7: Merging Stake Accounts

To merge the split stake accounts back together:

solana merge-stake -k my-wallet.json \
    $(solana address -k stake-account.json) \
    $(solana address -k split-stake-account.json)

You can verify the split by checking both accounts:

solana stake-account $(solana address -k stake-account.json)
solana stake-account $(solana address -k split-stake-account.json)

Step 8: Delegating to a Validator

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.

1. Finding a Validator

To find a validator, we use the command:

solana validators

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.

  1. Delegating Your Stake

    Once you've chosen a validator, use this command to delegate your stake:

    solana delegate-stake -k my-wallet.json \
        $(solana address -k stake-account.json) \
        <VOTE_ACCOUNT_ADDRESS>

    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.

Step 9: Deactivating the Delegation

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:

solana deactivate-stake -k my-wallet.json \
    $(solana address -k stake-account.json)

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:

    solana stake-account $(solana address -k stake-account.json)
  • 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.

Conclusion

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.

Practical Exam: Put Your Skills to the Test

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.

Your Mission

  1. Follow all the steps outlined in this lesson, from installing the Solana CLI to delegating your stake to a validator.

  2. Pay special attention to the delegation process and the resulting transaction.

  3. Locate your delegation transaction in the Solana explorer (remember to use the testnet explorer).

  4. Copy the link to your delegation transaction - you'll need this as proof of completion.

Quest Details and Submission

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.

Rewards

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.

Need Help?

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.

👨‍🔧
Write your address to the discord branch!
https://stakewiz.com
https://solanabeach.io
https://solscan.io/tx/5ZsugXEtPsjqS5r4vsxGcykbhjxr39Ehx3XDxcNnfuACR6qVcUPcDrwehKyUSpxY8KgVq4kCaeAoRv2io6ppVFrE?cluster=testnet
Solana CLI Staking Exam Quest
Exams channel.
solana-cli 1.18.22