Aptos
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
https://wallet-sdk-api.everstake.oneOption 2: JavaScript library
You can install and import Wallet SDK for Javascript.
Step. 1: Installing the Library
Install the npm library or yarn by copying the code below.
$ npm install @everstake/wallet-sdk$ yarn add @everstake/wallet-sdkStep. 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 { Aptos } from '@everstake/wallet-sdk';
// or you can also use
import * as Aptos from '@everstake/wallet-sdk/aptos';
// import needed function
import { stake } from '@everstake/wallet-sdk/aptos';Import ES5
// import module
const { Aptos } = require("@everstake/wallet-sdk");
// or you can also use
const { stake } = require("@everstake/wallet-sdk/aptos");Step. 3: Create Auth Token
In order to access all the features of the Wallet SDK, it's necessary for you to generate an authentication token. This token will be required in all of the methods you use.
Using JS Library
// import
const { CreateToken } = require("@everstake/wallet-sdk");
// Project name
const name = 'Everstake Wallet SDK';
// wallet | Dapp | Other
const type = 'SDK';
// Create Token - return token ID
const token = await CreateToken(name, type);
console.log(token); // 3155f389-d943-4966-8e18-f159c2a6ef66Using REST API (Swagger)
curl -X 'POST' \
'https://wallet-sdk-api.everstake.one/token/create' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"name": "Everstake Wallet SDK",
"type": "SDK"
}'Methods
Assets JS library methods
GetAssets(chain): The get Assets method provides information about the delegation pool.
Aptos JS library methods
stake(token, address, amount): Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.reactivate(token, address, amount): Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.unlock(token, address, amount): Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.unstake(token, address, amount): Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.sendTransfer(address, recipientAddress, amount): Transfers user tokens. Using this method user can transfer APT from one wallet address to another.getBalanceByAddress(address): Gets user balance.getStakeBalanceByAddress(address): Gets user stake balance.getMinAmountForStake(address): Gets user min amount for stake.getLockupSecs(): Get validator lockup timeout in seconds
Assets API methods
GetAssets(chain): The GET Assets method provides information about the delegation pool.
Aptos REST API methods
delegate(token, address, amount): Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.unlock(token, address, amount): Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.reactivateStake(token, address, amount): Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.undelegate(token, address, amount). Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.transfer(address, amount, recipientAddress): Transfers user tokens. Using this method user can transfer APT from one wallet address to another.getLockupSecs(): Gets a validator lockup expired period in secondsgetBalanceByAddress(address): Gets user balance.getStakeBalanceByAddress(address): Gets user stake balances.getMinAmountForStakeByAddress(address): Gets min amount to stake.
WARNING
Using REST API methods and JS library, you have to sign transaction on your side: see more
Stake
The stake namespace contains method used for sending transactions on delegation. The unique method to the stake namespace is:
stake(token, address, amount): Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.
Stake Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// Return min amount for stake by user address
const minAmount = await Aptos.getMinAmountForStake(address);
// The amount that the user stake
const amount = 11; // must be >= minAmount
// Stake - return Raw Transaction
const txnRequest = await Aptos.stake(token, address, amount);
console.log(txnRequest); // Raw Transaction ObjectUnstake
The unstake namespace contains method used for sending transactions on unstaking. The unique method to the unstake namespace is:
unstake(token, address, amount): Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.
Unstake Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// The amount that the user unstake
const amount = 11;
// Unstake - return Raw Transaction
const txnRequest = await Aptos.unstake(token, address, amount);
console.log(txnRequest); // Raw Transaction ObjectReactivate
The reactivate namespace contains method used for sending transactions on reactivating user stake. The unique method to the reactivate namespace is:
reactivate(token, address, amount): Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
Reactivate Stake Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// The amount that the user reactivate
const amount = 11;
// Reactivate - return Raw Transaction
const txnRequest = await Aptos.reactivate(token, address, amount);
console.log(txnRequest); // Raw Transaction ObjectUnlock Stake
The unlock namespace contains method used for sending transactions on unlocking. The unique method to the unlock namespace is:
unlock(token, address, amount): Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
Unlock state Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// The amount that the user unlock
const amount = 11;
// Unlock - return Raw Transaction
const txnRequest = await Aptos.unstake(token, address, amount);
console.log(txnRequest); // Raw Transaction ObjectSend Transfer
The transfer namespace contains method used for sending transfer. The unique method to the transfer namespace is:
sendTransfer(address, recipientAddress, amount): Transfers user tokens. Using this method user can transfer APT from one wallet address to another.
Transfer Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Recipient Address
const recipientAddress = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';
// The amount that the user want send
const amount = 10;
// Send Transfer - return Raw Transaction
const txnRequest = await Aptos.sendTransfer(address, recipientAddress, amount);
console.log(txnRequest); // Raw Transaction ObjectSign Transaction
Sign Transaction Code Example
try {
// import aptos lib
import aptos from "aptos";
// import SDK
import { NODE_URL, createClient, stake } from '@everstake/wallet-sdk/aptos';
// Optional
// 1. create client using aptos lib
// Node url you can use custom or import him
const client = new aptos.AptosClient(NODE_URL);
// 2. or create client using func createClient
// const client = createClient(NODE_URL);
// get UserAccount using user privateKey
const Uint8Array = aptos.HexString.ensure(privateKey).toUint8Array();
const UserAccount = new aptos.AptosAccount(Uint8Array);
// Raw Transaction
const txnRequest = await Aptos.stake(token, address, amount);
// Sign Transaction
const signedTxn = await client.signTransaction(UserAccount, txnRequest);
const transactionRes = await client.submitTransaction(signedTxn);
await client.waitForTransaction(transactionRes.hash);
return transactionRes.hash; // return hash
} catch (error) {
throw new Error(error);
}Getting Info
The get namespace contains method used for getting info. The unique method to the get namespace is:
getBalanceByAddress(address): Gets user balance.getStakeBalanceByAddress(address): Gets user stake balance.getMinAmountForStake(address): Gets user min amount for stake.getLockupSecs(): Gets a validator lockup expired period in seconds
Get Balance By Address Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';
// Return user balance in APT.
const getDelegationsResult = await Aptos.getBalanceByAddress(address);
console.log(getDelegationsResult); // "2.18" (Amount in APT)Get Min Stake Amount By Address Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';
// Return min amount for stake in APT.
const getMinAmountForStakeResult = await Aptos.getMinAmountForStake(address);
console.log(getMinAmountForStakeResult); // "11" | "0.1" (Amount in APT)Get Stake Balance By Address Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';
// Return user stake balance in APT.
const getStakeBalanceByAddressResult = await Aptos.getStakeBalanceByAddress(address);
console.log(getStakeBalanceByAddressResult); // see the response belowResponse Example
stake_balance = {
// after STAKE, one of `active` + `pending_active` stake
"active": "11",
// one of `inactive` stake FOR each past observed lockup cycle (OLC) on the stake pool
"inactive": "0",
// after UNLOCK, one of `pending_inactive` stake scheduled during this ongoing OLC
"pending_inactive": "20"
};Get a validator lockup expired period. Code Example
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';
const lockup = await Aptos.getLockupSecs(address);
console.log(lockup); // "3600" (1 hour before luckup expired)
