import { Helius } from 'helius-sdk';import { Keypair, Transaction } from '@solana/web3.js';import bs58 from 'bs58';// Initialize Helius clientconst helius = new Helius('YOUR_API_KEY');// Your wallet keypair (load from your secure storage)const payer = Keypair.fromSecretKey(/* your secret key */);
// Get all your Helius stake accountsconst 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
停用(开始解除质押)
Report incorrect code
Copy
Ask AI
// Begin the unstaking processconst 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.');
// Get instructions instead of full transactionconst { instructions, stakeAccount } = await helius.rpc.getStakeInstructions( wallet.publicKey, stakeAmount);// Let the wallet handle transaction building and signingconst transaction = new Transaction().add(...instructions);// Sign with wallet adapterconst signature = await wallet.sendTransaction(transaction, connection);console.log(`Stake account: ${stakeAccount.publicKey.toBase58()}`);