零佣金验证器:使用 Helius 验证器进行质押,享受 0% 佣金率,保留 100% 的质押奖励。

快速概览

Helius SDK 提供简单的方法以编程方式处理完整的 SOL 质押生命周期。非常适合构建质押界面、DeFi 协议或自动化质押策略。

创建与委托

在一次交易中设置新的质押账户并委托给验证器

监控与管理

跟踪奖励、检查状态并管理现有质押账户

提现与赎回

在冷却期后停用质押并提取 SOL

安装与设置

npm install helius-sdk @solana/web3.js bs58
import { Helius } from 'helius-sdk';
import { Keypair, Transaction } from '@solana/web3.js';
import bs58 from 'bs58';

// Initialize Helius client
const helius = new Helius('YOUR_API_KEY');

// Your wallet keypair (load from your secure storage)
const payer = Keypair.fromSecretKey(/* your secret key */);

质押基础

入门指南

仅需三行代码即可质押 SOL:
// 1. Create the staking transaction
const { serializedTx, stakeAccountPubkey } = 
  await helius.rpc.createStakeTransaction(payer.publicKey, 1.5);

// 2. Sign and send
const tx = Transaction.from(bs58.decode(serializedTx));
tx.partialSign(payer);
const signature = await helius.connection.sendRawTransaction(tx.serialize());

console.log(`Staked! Transaction: ${signature}`);
console.log(`Stake Account: ${stakeAccountPubkey}`);
SDK 会自动处理租金计算和质押账户创建。1.5 参数是您想要质押的 SOL 数量。

SDK 方法参考

完整质押工作流程

1

创建和委托

// Stake 2 SOL to Helius validator
const { serializedTx, stakeAccountPubkey } = 
  await helius.rpc.createStakeTransaction(payer.publicKey, 2.0);

const tx = Transaction.from(bs58.decode(serializedTx));
tx.partialSign(payer);

const signature = await helius.connection.sendRawTransaction(tx.serialize());
console.log(`Stake created: ${stakeAccountPubkey}`);
2

监控您的质押

// Get all your Helius stake accounts
const accounts = await helius.rpc.getHeliusStakeAccounts(
  payer.publicKey.toBase58()
);

console.log(`You have ${accounts.length} active stake accounts`);

accounts.forEach((account, index) => {
  const info = account.account.data.parsed.info;
  const delegation = info.stake.delegation;
  
  console.log(`Stake ${index + 1}:`);
  console.log(`  Amount: ${delegation.stake / LAMPORTS_PER_SOL} SOL`);
  console.log(`  Activated: Epoch ${delegation.activationEpoch}`);
  console.log(`  Status: ${info.meta.lockup.unixTimestamp === 0 ? 'Active' : 'Locked'}`);
});
3

停用(开始解除质押)

// Begin the unstaking process
const unstakeTx = await helius.rpc.createUnstakeTransaction(
  payer.publicKey,
  stakeAccountPubkey
);

const tx = Transaction.from(bs58.decode(unstakeTx));
tx.partialSign(payer);

await helius.connection.sendRawTransaction(tx.serialize());
console.log('Deactivation started. Will be withdrawable next epoch.');
4

提取 SOL

// Check withdrawable amount
const withdrawable = await helius.rpc.getWithdrawableAmount(
  stakeAccountPubkey, 
  true  // include rent
);

if (withdrawable > 0) {
  // Create withdrawal instruction
  const withdrawInstruction = helius.rpc.getWithdrawInstruction(
    payer.publicKey,
    stakeAccountPubkey,
    payer.publicKey,  // withdraw to same wallet
    withdrawable
  );
  
  // Send using Smart Transactions for better reliability
  const signature = await helius.rpc.sendSmartTransaction(
    [withdrawInstruction], 
    [payer]
  );
  
  console.log(`Withdrawn ${withdrawable / LAMPORTS_PER_SOL} SOL`);
}

高级模式

对于使用钱包适配器的浏览器应用程序:
// Get instructions instead of full transaction
const { instructions, stakeAccount } = await helius.rpc.getStakeInstructions(
  wallet.publicKey,
  stakeAmount
);

// Let the wallet handle transaction building and signing
const transaction = new Transaction().add(...instructions);

// Sign with wallet adapter
const signature = await wallet.sendTransaction(transaction, connection);

console.log(`Stake account: ${stakeAccount.publicKey.toBase58()}`);

重要提示

Epoch 时间:Solana 的 epoch 大约持续 2 天。质押在下一个 epoch 开始时激活,停用在当前 epoch 结束时生效。
租金考虑:质押账户需要租金豁免储备(约 0.00228 SOL)。提取全部余额将关闭账户。
硬件钱包:用户将看到两个签名提示 - 一个用于质押账户(预签名),另一个用于费用支付者。请相应设计您的用户体验。

快速参考

需要快速提醒吗?以下是基本方法:
// Stake SOL
await helius.rpc.createStakeTransaction(owner, amountInSol);

// Check your stakes  
await helius.rpc.getHeliusStakeAccounts(ownerAddress);

// Start unstaking
await helius.rpc.createUnstakeTransaction(owner, stakeAccount);

// Check withdrawable amount
await helius.rpc.getWithdrawableAmount(stakeAccount, includeRent);

// Withdraw SOL
helius.rpc.getWithdrawInstruction(owner, stakeAccount, destination, amount);

下一步