Staking: A Quick Start

In this guide, you'll learn how to integrate customer staking into your website to allow your customers to stake their SOL tokens on Solana. It covers all the essentials to get you up to speed in just a few minutes.

👍

Important

This staking process is designed for institutions that want to offer non-custodial staking services to their customers. With this system, customers maintain control of their own wallets and funds.

What’s Staking on Solana?

Staking in a blockchain protocol is the process of participating in transaction validation and network security. When you stake, you lock up (or 'delegate') an amount of the blockchain's native currency - in Solana's case, SOL - to act as collateral. This staked collateral helps ensure validators behave honestly, as they risk losing their stake if they attempt to harm the network.

Running a Solana validator node is particularly resource-intensive compared to other blockchain networks:

  • High-performance CPU requirements (minimum 12 cores/24 threads)
  • Substantial RAM needs (128GB minimum, 256GB recommended)
  • Fast SSD storage (PCIe Gen3 x4 NVME SSD with 1TB+ capacity)
  • High-bandwidth internet connection (1 Gbps+ recommended)

Because of these demanding requirements, most SOL holders choose to delegate their tokens to existing validators rather than running their own node.

This delegation process:

  • Allows token holders to earn staking rewards without operating infrastructure
  • Helps secure the network by increasing the total stake
  • Promotes decentralization by supporting diverse validators
  • Typically yields 4-8% annual returns (varies based on network conditions)

Create Delegation

The first step for delegating your SOL tokens to Stakefish is to request our API to build the delegation transaction.

Send the following request to our API:

curl -X POST \
  'https://api.stake.fish/v1/solana/delegations/delegate' \
  -H 'Content-Type: application/json' \
  -d '{
    "stakeAuthorityPubkey": STAKE_AUTHORITY_PUBKEY,
    "amountToStake": STAKE_AMOUNT_IN_LAMPORTS
  }'

📘

Important

This API requires Public API Key.

Required Fields:

  • amountToStake: The amount to stake in lamports (Solana's smallest unit)
    • 1 SOL = 1,000,000,000 lamports
      Example: To stake 1 SOL, enter 1,000,000,000 lamports
  • stakeAuthorityPubkey: The public key that will control the stake account
    • Acts as the owner of the delegation
    • Has full authority over the stake account & must be securely stored

Optional Fields:

  • fromPubkey: The public key that will fund the transaction
    • Must have sufficient balance to cover the stake amount and transaction fees
    • If not specified, defaults to stakeAuthorityPubkey

Example Response:

After sending the POST request, you’ll receive a response similar to the following:

{
  "serializedTransaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAcJ2Lx+M8MXGtW3wB5waOuJFc6RfRLUa+geZVOndWla1FnZCH7dHoNDHlIPWHBmK6xI9jAxw5LZZ1dY3qaY/1NgOwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYGPfUNuv5FIOsgxu1spvxVhlhqZrI2JJujUn/UMSx0EGodgXkTdUKpg0N73+KnqyVX9TXIp4citopJ3AAAAAAAah2BelAgULaAeR5s5tuI4eW3FQ9h/GeQpOtNEAAAAABqfVFxjHdMkoVmOYaR1etoteuKObS21cc1VbIQAAAAAGp9UXGSxcUSGMyUw9SvF/WNruCJuh/UTj29mKAAAAAAan1RcZNYTQ/u2bs0MdEyBr5UQoG1e4VmzFN1/0AAAAMKk3GxmHF4T2PO02tbVAEVS1XJANrnS4smv6e2aHoSQDAgIAAXADAAAA2Lx+M8MXGtW3wB5waOuJFc6RfRLUa+geZVOndWla1FkUAAAAAAAAAHNmIHN0YWtlOiAxNzMxMzYzODQ1AOH1BQAAAADIAAAAAAAAAAah2BeRN1QqmDQ3vf4qerJVf1NcinhyK2ikncAAAAAABAIBB3QAAAAA2Lx+M8MXGtW3wB5waOuJFc6RfRLUa+geZVOndWla1FnYvH4zwxca1bfAHnBo64kVzpF9EtRr6B5lU6d1aVrUWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQGAQMGCAUABAIAAAA=",
  "stakeAccountPubkey": "FcCz4wuwaQV4GNoRtAfTqgH67mpoD58vGDQFg9qhsvup",
  "voteAccountPubkey": "7VGU4ZwR1e1AFekqbqv2gvjeg47e1PwMPm4BfLt6rxNk"
}

Sign & Broadcast transaction

Once the transaction is prepared by our API, the final step is to sign and broadcast the transaction in order to initialize your delegation.

Sign The Transaction:

Rehydrate the serialized transaction from the Base64 encoded wire transaction.

Use the same account which corresponds to the fromPubkey(which defaults to the stakeAuthorityPubkey ) as provided when creating the transaction.

Send the Transaction

Broadcast the transaction to a Solana node. The operation is completely atomic which means that once the transaction succeeds your delegation process is complete.

ℹ️

Occasional failures are expected when broadcasting the transaction - when this occurs please follow the suggested guidance

Here’s the completed code snippet, using the @solana/web3.js:

import { Keypair, Transaction, Connection } from "@solana/web3.js";
import bs58 from "bs58";

const connection = new Connection("https://api.mainnet-beta.solana.com");

const MY_BASE58_SOLANA_SECRET_KEY =
  "YOUR SECRET KEY HERE";

const AMOUNT_TO_STAKE_LAMPORTS = "AMOUNT TO STAKE HERE";
const wallet = Keypair.fromSecretKey(bs58.decode(MY_BASE58_SOLANA_SECRET_KEY));

const body = JSON.stringify({
  stakeAuthorityPubkey: wallet.publicKey.toString(),
  amountToStake: AMOUNT_TO_STAKE_LAMPORTS,
});

const response = await fetch("https://api.staging.stake.fish/v1/solana/delegations/delegate", {
  method: "POST",
  headers: new Headers({
    "Content-Type": "application/json",
  }),
  body,
})
  .then((response) => response.json())
  .catch((error) => console.error(error));

const serializedTransaction = Buffer.from(
  response.serializedTransaction,
  "base64"
);

const rehydratedTransaction = Transaction.from(serializedTransaction);

rehydratedTransaction.sign(wallet);

const transactionSignature = await connection.sendRawTransaction(
  rehydratedTransaction.serialize()
);

console.log({ transactionSignature });

Configuration:

  • MY_BASE58_SOLANA_SECRET_KEY: Your Solana secret key
    • Used to pay for the transaction
    • Becomes the stake authority
    • ⚠️ Note: This example uses a direct secret key for backend demonstration. For web applications, use wallet-adapter instead to handle user signatures securely.
  • AMOUNT_TO_STAKE_LAMPORTS: Stake amount in lamports
    • Must be specified in lamports (Solana's smallest unit)
    • 1 SOL = 1,000,000,000 lamports. Example: 1.5 SOL = 1,500,000,000 lamports

Final Steps

After sending the transaction, you'll receive a transaction signature. Use this signature to monitor the transaction status on your chosen Solana explorer or directly via the @solana/web3.jslibrary.

Delegation Activation: After your transaction is confirmed, your delegation remains pending until the next epoch begins (epochs last ~48 hours). Once the new epoch starts, your delegation automatically activates and begins earning rewards.


What’s Next