Solana
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.oneOption 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.xStep. 1: Installing the Library
Install the npm library or yarn by copying the code below.
$ npm install @everstake/wallet-sdk-solana$ yarn add @everstake/wallet-sdk-solanaStep. 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 module
import { Solana } from "@everstake/wallet-sdk-solana";Import ES5
// import module
const { Solana } = require("@everstake/wallet-sdk-solana");
// Select network: "mainnet-beta" | "devnet"
const network = "mainnet-beta";
// Create SDK instance
const solanaClient = new Solana(network);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
// 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 ObjectStake
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
// 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 ObjectDeactivate
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
// 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 ObjectUnstake
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
// 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 ObjectClaim
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
// Import SDK
import { Solana } from "@everstake/wallet-sdk-solana";
// User wallet address.
const address = "exampleCnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94";
// Select network: "mainnet-beta" | "devnet"
const network = "mainnet-beta";
// Create SDK instance
const solanaClient = new Solana(network);
const claim = await solanaClient.claim(address);
console.log(claim); // Raw Transaction ObjectWithdraw
The withdraw namespace contains methods used for sending transactions. The unique method to the withdraw namespace is:
withdraw(address, stakeAccountPublicKey, stakeBalance): Withdraw user's tokens.
Withdraw Code Example
// 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 ObjectGetting Info
The get namespace contains method used for getting info. The unique methods to the get namespace is:
getDelegations(address): Get all user delegations.
Getting Info Code Example
// 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 belowResponse Example
getDelegationsResult = {
result: [
{
account: null,
data: {
parsed: {
info: {
meta: {
authorized: {
staker: "CnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94example",
withdrawer: "CnpYVG5ukLQsfusLqMGFRm5kJwcNhVdA3NS94example",
},
lockup: {
custodian: "11111111111111111111111111111111",
epoch: 0,
unixTimestamp: 0,
},
rentExemptReserve: "2282880",
},
stake: {
creditsObserved: 140045079,
delegation: {
activationEpoch: "399",
deactivationEpoch: "400",
stake: "2300000",
voter: "9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF",
warmupCooldownRate: 0.25,
},
},
},
type: "delegated",
},
program: "stake",
space: 200,
},
executable: false,
lamports: 4582880,
owner: "Stake11111111111111111111111111111111111111",
rentEpoch: 0,
pubkey: "CTZ4dbobNAec3fikKLFaXscPNqUzLmdLTzhNxrz4RTBh",
},
],
};
