How to Stake With Helius Programmatically
Learn how to stake SOL on Solana using the Helius Node.js SDK with clean, programmatic flows
Welcome, Solana builder 👋 You are about to give your users a single-click staking flow while keeping full programmatic control in your codebase. The Helius Node.js SDK already wraps every low-level detail, so your job is mostly to decide when to call each helper and who signs the resulting transaction
This guide starts with general information about staking on Solana, then shows how to install the SDK, and finally walks through the full staking lifecycle with practical examples
1. Staking on Solana
- Stake account
A special account that locks up SOL. The SOL inside is delegated to a validator of your choice. You can have as many stake accounts as you like and each one points at exactly one validator - Rewards
The validator earns rewards for producing blocks. Those rewards flow back into every stake account that selected that validator. When you use the Helius validator the commission rate is 0 %, so users keep everything - Life-cycle
1 ) Create and delegate
2 ) Cool down (optional deactivation)
3 ) Withdraw or re-delegate
The helper methods map to these exact lifecycle phases
2. One-time Setup
From this point on, every snippet will assume you imported this helius
instance and that you hold a funded Keypair
called payer
.
3. Method Reference with Example Calls
createStakeTransaction
Builds a serialized, unsigned transaction that creates a new stake account, and delegates it to the Helius validator
Example call:
Return value:
getStakeInstructions
The same as createStakeTransaction, except it only returns the TransactionInstruction[]
. This is useful inside browser wallets that construct their own transaction object, or pairing with the SDK’s smart transactions
Example call:
Return value:
createUnstakeTransaction
Builds a serialized, unsigned transaction that sends a Deactivate
instruction to an existing stake account
Example call:
Return value:
getUnstakeInstruction
Single Deactivate
instruction with no wrapper transaction
Example call:
Return value:
getWithdrawableAmount
Returns the number of lamports that can be withdrawn right now from a given stake account. Pass true
to include the rent-exempt minimum into the withdrawable amount
Example call:
Return value:
createWithdrawTransaction
Builds a serialized, unsigned transaction that moves lamports out of a stake account into any destination address. Works only after the cooldown period has ended
Example call:
Return value:
getWithdrawInstruction
Stand-alone withdraw instruction
Example call:
Return value:
getHeliusStakeAccounts
Returns all stake accounts that are currently delegated to the Helius validator for a given wallet
Example call:
Return value:
4. Quickstart: Stake in Three Simple Steps
5. Full Lifecycle Cookbook
5.1 Fetch every stake account that delegates to Helius for a given wallet
5.2 Deactivate (begin cooldown)
5.3 Check how many lamports can be withdrawn
5.4 Withdraw part, or all, of the balance
6. Power User Patterns
7. Common Pitfalls
-
Epoch timing
A Solana epoch lasts roughly two days. If you deactivate halfway through epoch 600, the stake stays locked until epoch 601 begins -
Rent exempt minimum
The stake account will be closed if you withdraw the full balance, including rent. If you withdraw less than the rent-exempt threshold, the account will remain open -
Hardware wallets
Users see two prompts: one signature for the new stake account (already signed within the blob) and one for the fee payer. Make sure your UX explains this
8. One-page Cheat Sheet
Next Steps
Helius SDK
Full reference documentation for the Helius SDK
Discord
Join our developer chat for support and questions
Happy building and happy earning!