Learn how to integrate Solana staking using Everstake Wallet SDK.
Getting Started
You can use two different options to implement staking for Everstake validator.
Option 1: REST API
You can use REST API to call methods which are described in Swagger with detailed examples (both v1 and v2 are supported).
https://wallet-sdk-api.everstake.one
Option 2: JavaScript library
You can install and import Wallet SDK for Javascript.
Choose the version according to the Solana version you're working with
@everstake/wallet-sdk-solana@^1.x.x
@everstake/wallet-sdk-solana@^2.x.x
Step. 1: Installing the Library
Install the npm library or yarn by copying the code below.
$npminstall@everstake/wallet-sdk-solana
$yarnadd@everstake/wallet-sdk-solana
Step. 2: Import Wallet SDK
After installing the app, you can import module of needed blockchain (Ethereum, Aptos, Solana, Cosmos, Polygon are available) and use the SDK:
Import ES6
Import ES5
Delegate
The delegate namespace contains method used for sending transactions on delegation. The unique method to the delegate namespace is:
createAccount(address, lamports): Create Account for Delegate user tokens.
delegate(address, lamports, stakeAccount): Delegate user tokens.
Delegate Code Example
Stake
The stake namespace contains method used for sending transactions on stake. This method includes createAccount and delegation together. The unique method to the stake namespace is:
stake(address, lamports, source): Stake user tokens.
Stake Code Example
Deactivate
The deactivate namespace contains method used for deactivation of the user stake account. The unique method to the deactivate namespace is:
deactivate(address, stakeAccountPublicKey): Deactivate user stake account.
Deactivate Code Example
Unstake
The unstake namespace contains methods used for sending transactions to unstake tokens. The unique method to the unstake namespace is:
unstake(address, lamports): Unstake user tokens.
Unstake Code Example
Claim
The claim namespace contains methods used for claiming rewards from staking accounts. The unique method to the claim namespace is:
claim(address): Claim rewards for a staking account.
Claim Code Example
Withdraw
The withdraw namespace contains methods used for sending transactions. The unique method to the withdraw namespace is:
// 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);
// User wallet address.
const address = "exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94";
// The amount that the user delegates.
const lamports = 1000000000; // min value 0.01 (SOL)
// partner ID
const source = "99";
// return createStakeAccountTx - Raw Transaction and stakeAccount - address
const createAccount = await solanaClient.createAccount(
address,
lamports,
source
);
// { result: createStakeAccountTx, stakeAccount }
const delegate = await solanaClient.delegate(
address,
lamports,
createAccount.result.stakeAccount
);
console.log(delegate); // Raw Transaction Object
// Import SDK
import { Solana } from "@everstake/wallet-sdk-solana";
// User wallet address.
const address = "exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94";
// The amount that the user delegates.
const lamports = 1000000000; // min value 0.01 (SOL)
// Your source identificator
const source = "99";
// Select network: "mainnet-beta" | "devnet"
const network = "mainnet-beta";
// Create SDK instance
const solanaClient = new Solana(network);
const stake = await solanaClient.stake(address, lamports, source);
console.log(stake); // Raw Transaction Object
// 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 deactivated
const stakeAccountPublicKey =
getDelegations.result[0].data.pubkey ||
"AidgPiAZMLbqtNdGzt5CfBbtMjvFugnCcr116PXpCCnm";
// deactivateResp - return Raw Transaction
const deactivateResp = await solanaClient.deactivate(
address,
stakeAccountPublicKey
);
console.log(deactivateResp); // Raw Transaction Object
// Import SDK
import { Solana } from "@everstake/wallet-sdk-solana";
// User wallet address.
const address = "exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94";
// The amount that the user wants to unstake.
const lamports = 500000000; // min value 0.01 (SOL)
// Select network: "mainnet-beta" | "devnet"
const network = "mainnet-beta";
// Create SDK instance
const solanaClient = new Solana(network);
const unstake = await solanaClient.unstake(address, lamports);
console.log(unstake); // Raw Transaction Object
// 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
// 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);
// User wallet address.
const address = "CnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94example";
// Get all user delegations.
const getDelegationsResult = await solanaClient.getDelegations(address);
console.log(getDelegationsResult); // see response example below