Liquid Staking SDK
Integrating with Ankr Liquid Staking has become easier.
Now you can skip the complications of Solidity and learning how to send direct calls to Liquid Staking smart contracts. Instead, use Liquid Staking SDK — an npm package with compound and comprehensible JS methods that take care of the low-level logic for you.
Multiple network support
Liquid Staking SDK supports multiple networks and allows you to interact with:
- Avalanche blockchain: aAVAXb/ankrAVAX tokens and Avalanche Liquid Staking contracts.
- Binance blockchain: aBNBb/ankrBNB tokens and Binance Liquid Staking contracts.
- Ethereum blockchain: aETHb/ankrETH tokens and Ethereum Liquid Staking contracts;
- Fantom blockchain: aFTMb/ankrFTM tokens and Fantom Liquid Staking contracts.
- Ethereum and Polygon blockchains: ankrPOL tokens, and Polygon Liquid Staking contracts.
-b tokens are not actively supported anymore, and we're discontinuing their support in the SDK. We recommend you switch any -b tokens for ankr- tokens (opens in a new tab) and disable any -b-token-related methods you adopted from our SDK.
Install and integrate
To integrate with the SDK, install the SDK npm package (opens in a new tab):
# yarn
yarn add @ankr.com/staking-sdk reselect
# npm
npm i @ankr.com/staking-sdk reselect
To interact with the Testsnet smart contracts, use the REACT_APP_API_ENV=staging
environment variable. For Mainnet smart contracts, use REACT_APP_API_ENV=prod
.
Usage examples
Here are some reference examples on how to user Liquid Staking SDK in your project.
Live sample
Use the codesandbox get balance sample (opens in a new tab) as specific live example of interacting with @ankr.com/staking-sdk
.
Polygon (on Ethereum)
- Stake ankrPOL token:
import { PolygonOnEthereumSDK } from '@ankr.com/staking-sdk'; const sdk = await PolygonOnEthereumSDK.getInstance(); const { txHash } = await sdk.stake(new BigNumber(1_200), 'aPOLc');
- Unstake ankrPOL token:
import { PolygonOnEthereumSDK } from '@ankr.com/staking-sdk'; const sdk = await PolygonOnEthereumSDK.getInstance(); await sdk.unstake(new BigNumber(1_200), 'aPOLc');
- Get POL transaction history:
import { PolygonOnEthereumSDK } from '@ankr.com/staking-sdk'; const sdk = await PolygonOnEthereumSDK.getInstance(); const history = await sdk.getTxEventsHistory();
Binance
- Stake ankrBNB token:
import { BinanceSDK } from '@ankr.com/staking-sdk'; const sdk = await BinanceSDK.getInstance(); const { txHash } = await sdk.stake(new BigNumber(1_200), 'aBNBc');
- Unstake ankrBNB token:
import { BinanceSDK } from '@ankr.com/staking-sdk'; const sdk = await BinanceSDK.getInstance(); await sdk.unstake(new BigNumber(1_200), 'aBNBc');
- Switch aBNBb and ankrBNB:
import { BinanceSDK } from '@ankr.com/staking-sdk'; const sdk = await BinanceSDK.getInstance(); const lockResponse = await sdk.lockShares({ amount: new BigNumber(2.65) }); const unlockResponse = await sdk.unlockShares({ amount: new BigNumber(1.98) });
- Get BNB transaction history:
import { BinanceSDK } from '@ankr.com/staking-sdk'; const sdk = await BinanceSDK.getInstance(); const history = await sdk.getTxEventsHistory();
Ethereum
- Stake ankrETH token:
import { EthereumSDK } from '@ankr.com/staking-sdk'; const sdk = await EthereumSDK.getInstance(); const { txHash } = await sdk.stake(new BigNumber(1_200), 'aETHc');
- Switch ankrETH and aETHb:
import { EthereumSDK } from '@ankr.com/staking-sdk'; const sdk = await EthereumSDK.getInstance(); const lockResponse = await sdk.lockShares({ amount: new BigNumber(2.65) }); const unlockResponse = await sdk.unlockShares({ amount: new BigNumber(1.98) });
Misc
- Define specific providers:
import { PolygonOnEthereumSDK, Web3KeyReadProvider, Web3KeyWriteProvider } from '@ankr.com/staking-sdk'; const readProvider: Web3KeyReadProvider = { ... }; const writeProvider: Web3KeyWriteProvider = { ... }; const sdk = await PolygonOnEthereumSDK.getInstance({ readProvider, writeProvider }); const { txHash } = await sdk.stake(new BigNumber(1_200), 'aPOLc');
Reference
For detailed information on supported methods and parameters, refer to:
- AvalancheSDK reference
- BinanceSDK reference
- EthereumSDK reference
- FantomSDK reference
- PolygonSDK for Ethereum reference
- PolygonSDK for Polygon reference
Flow
To understand the processes and mechanics of Liquid Staking, refer to: