Staking Guide
Simplifying Solana Staking
Staking
Staking on Solana involves delegating your SOL to a validator to help secure the network and earn rewards. This is done using the Stake API, which returns an unsigned transaction. You must sign and broadcast this transaction with your wallet's private key. Once confirmed, your SOL is actively staked and starts earning rewards from the next epoch.
Supported Environments
Luganodes supports the following environments on SOL, as defined below
Solana Mainnet
Step:
Call Stake API → sign & broadcast the transaction
Script for signing and broadcasting unsigned stake transaction
import { Connection, Transaction, Keypair } from "@solana/web3.js";
import dotenv from "dotenv";
import bs58 from "bs58";
dotenv.config();
// Connect to the Solana cluster
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const walletKeypair = Keypair.fromSecretKey(
bs58.decode(process.env.SOLANA_PRIVATE_KEY)
);
const unsignedTransaction = ""; //paste unsigned transaction here
const decodedTransaction = Buffer.from(unsignedTransaction, "base64");
const transaction = Transaction.from(decodedTransaction);
transaction.partialSign(walletKeypair);
(async () => {
const txSignature = await connection.sendRawTransaction(
transaction.serialize()
);
console.log(`Transaction sent: https://solscan.io/tx/${txSignature}`);
})();
Unstaking
Unstaking is a two-step process: Deactivation followed by Withdrawal. First, use the Deactivate API to stop the validator from using your stake—this begins the cooldown period (typically 1 epoch). Once the stake is fully deactivated, use the Withdraw API to transfer your SOL back to your wallet. Both steps return unsigned transactions that must be signed and broadcasted.
Steps:
Call Deactivate API → sign & broadcast
Wait for deactivation to complete (check with Balance API for
status
of stake account if needed)Call Withdraw API → sign & broadcast the transaction
Script for signing and broadcasting unsigned deactivate and withdraw transaction
import { Connection, Transaction, Keypair } from "@solana/web3.js";
import dotenv from "dotenv";
import bs58 from "bs58";
dotenv.config();
// Connect to the Solana cluster
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const walletKeypair = Keypair.fromSecretKey(
bs58.decode(process.env.SOLANA_PRIVATE_KEY)
);
const unsignedTransaction = ""; //paste unsigned transaction here
const decodedTransaction = Buffer.from(unsignedTransaction, "base64");
const transaction = Transaction.from(decodedTransaction);
transaction.Sign(walletKeypair);
(async () => {
const txSignature = await connection.sendRawTransaction(
transaction.serialize()
);
console.log(`Transaction sent: https://solscan.io/tx/${txSignature}`);
})();
Last updated