Skip to main content

Staking & UnStaking


1. Initialize the library

import { SolidoSDK } from '@lidofinance/solido-sdk';
import { Connection } from '@solana/web3.js';

// Change rpc endpoint to yours, or whole connection
const connection = new Connection('https://test.rpcpool.com');

const solidoSDK = new SolidoSDK('mainnet-beta', connection, 'your_solana_referral_address');

2. Call stake method

try {
const transactionHash = await solidoSDK.stake({
amount: 20, // The amount of SOL-s which need to stake
wallet: wallet, // Wallet instance
setTxStage: setTxStageCallback, // Optional callback for getting information about transaction stage (see TX_STAGE)
});
} catch (e) {
// Handle Errors
}
caution

You may get exception if amount exceed maximum available SOL-s in balance. In order to prevent this exception, you can call

const maxStakeAmount = await solidoSDK.calculateMaxStakeAmount(new PublicKey(wallet.publicKey));

Unstaking

Unstaking process if whole the same as staking, also arguments are the same, just methods rename:

  • getStakeTransaction => getUnStakeTransaction
  • calculateMaxStakeAmount => calculateMaxUnStakeAmount
  • stake => unStake

enum TX_STAGE {
AWAITING_SIGNING = 1,
AWAITING_BLOCK = 2,
SUCCESS = 3,
ERROR = 4,
}