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-solana";

// Select network: "mainnet-beta" | "devnet"
const network = "mainnet-beta";

// Create SDK instance
const solanaClient = new Solana(network);

// You can get Stake Account Public Key and all user delegations.
// User wallet address.
const address = "exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94";
// Get all user delegations.
const getDelegations = await solanaClient.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 solanaClient.withdraw(
  address,
  stakeAccountPublicKey,
  stakeBalance
);
console.log(withdrawResp); // Raw Transaction Object