Skip to content
On this page

Withdraw Solana

The withdraw namespace contains methods used for sending transactions. The unique method to the withdraw namespace is:

withdraw(token, address, stakeAccountPublicKey, stakeBalance): Withdraw user's tokens.

Withdraw Code Example

ts
// Import SDK
import { Solana } from '@everstake/wallet-sdk';

// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// You can get Stake Account Public Key and all user delegations.
// User wallet address.
const address = 'exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94';
// Get all user delegations.
const getDelegations = await Solana.getDelegations(address);

// User Stake Account Public Key, which should be withdrawn
const stakeAccountPublicKey =
    getDelegations.result[0].data.pubkey
    || 'AidgPiAZMLbqtNdGzt5CfBbtMjvFugnCcr116PXpCCnm';

// User Stake Account Balance, which should be withdraw
const stakeBalance =
    getDelegations.result[0].data.parsed.stake.stake
    || '2300000'; // String, value in lamports (0.0023 SOL * 1000000000)

// Withdraw user's tokens - return Raw Transaction
const withdrawResp = await Solana.withdraw(
    token,
    address,
    stakeAccountPublicKey,
    stakeBalance
);
console.log(withdrawResp); // Raw Transaction Object