Documentation v1.0 has been released! Staking Guide, Protocols, Glossary, FAQ, and Support sections have been added.

Polygon

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.one

Option 2: TypeScript library

You can install and import Wallet SDK for Javascript/TypeScript.

Step. 1: Installing the Library

Install the npm library or yarn or pnpm by copying the code below.

$ npm install @everstake/wallet-sdk-polygon

Step. 2: Import Wallet SDK

After installing the app, you can import module Polygon and use the SDK:

Import ES6

// import modules
import { Polygon } from '@everstake/wallet-sdk-polygon';

Import ES5

// import modules
const { Polygon } = require('@everstake/wallet-sdk-polygon');

Questions and Feedback

If you have any questions, issues, or feedback, please file an issue on GitHub.

Stake

The delegate namespace contains methods used for sending transactions on delegation. The unique methods to the delegate namespace are:

  • approve(address, amount, isPOL = false): Approval of the amount for further debiting by a smart contract.

  • delegate(address, amount, isPOL = false): Delegate user tokens.

Delegate Code Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

const address = '2f92e...6761b'

// The amount that the user delegates.
const amountDelegate = 10; // min value 1 (MATIC)

// Step 1 - Approve - if it is already approved returns 'approve' or transaction
const approve = await Polygon.approve(address, amountDelegate, false);
console.log(approve); // { result: 'approve' } or Raw Transaction

// Step 2 - Delegate - return Raw Transaction
const delegate = await Polygon.delegate(address, amountDelegate, false);
console.log(delegate); // Raw Transaction Object

Undelegate

The transaction namespace contains methods used for sending transactions. The unique method to the transaction namespace is:

undelegate(address, amount, isPOL = false): Undelegate user's tokens.

Undelegate Code Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

const address = '2f92e...6761b'

// The amount that the user undelegates.
const amountUndelegate = 5;

// Undelegate user's tokens - return transaction
const undelegateResp = await Polygon.undelegate(address, amountUndelegate, false);
console.log(undelegateResp); // Raw Transaction

Reward

The transaction namespace contains methods used for sending transactions. The unique method to the transaction namespace is:

reward(address, isPOL = false): Reward user tokens (Claim reward).

Claim Reward Code Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

const address = '2f92e...6761b'

// Reward user tokens - return transaction
const rewardResp = await Polygon.reward(address, false);
console.log(rewardResp); // Raw Transaction

Restake

The transaction namespace contains methods used for sending transactions. The unique method to the transaction namespace is:

restake(address, isPOL = false): Restake user tokens (Claim reward and auto delegate them).

Restake Code Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

const address = '2f92e...6761b'

// Restake user tokens - return transaction
const restakeResp = await Polygon.restake(address, false);
console.log(restakeResp); // Raw Transaction

Claim Undelegate

The claimUndelegate method uses for sending transaction on claim undelegation.

  • claimUndelegate(address, unbondNonce = 0, isPOL = false): Claim undelegation by address

Claim Undelegate Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

const address = '2f92e...6761b'

const nonce = await Polygon.getUnbondNonces(address);

const claim = await Polygon.claimUndelegate(address, nonce, false);
console.log(claim); // Raw Transaction Object

Getting Info

The get namespace contains methods used for getting info. The unique methods to the get namespace are:

  • getReward(address): Gets the user's reward balance in tokens.

  • getTotalDelegate(address): Gets the user's delegate balance in tokens.

  • getUnbond(address): Gets the user's unbond balance in tokens.

  • getCurrentEpoch(): Gets current epoch.

  • getBalanceOf(address, isPOL = false): Gets the user's balance

  • getUnbondNonces(address): Gets unbound nonce by address

Getting Info Code Example

// Import SDK
import { Polygon } from '@everstake/wallet-sdk-polygon';

// User wallet address.
const address = '0x4D3F0BF20Dd5DA8C6800c5cA17d721131E366651';

// Gets the user's reward balance in tokens.
const getReward = await Polygon.getReward(address);
console.log(getReward); // BigNumber(3.34) (MATIC)

// Gets the user's delegate balance in tokens.
const getTotalDelegate = await Polygon.getTotalDelegate(address);
console.log(getTotalDelegate); // BigNumber(20.5) (MATIC)

// Gets the user's unbond balance in tokens.
const getUnbond = await Polygon.getUnbond(address);
console.log(getUnbond); // BigNumber(2.2) (MATIC)

// Gets current epoch.
const epoch = await Polygon.getCurrentEpoch();
console.log(epoch); // 999

// Gets current balance.
const balance = await Polygon.getBalanceOf(address, false);
console.log(balance); // BigNuber(100.2) (MATIC)

// Gets unbound nonce.
const nonce = await Polygon.getUnbondNonces(address);
console.log(nonce); // "5"

Loading Transaction

The loading namespace contains method used for getting info about loading transaction. The unique methods to the loading namespace is:

  • isTransactionLoading(hash): Waits for a transaction to be processed and returns the status of the transaction.

Get Status Transaction

// Import SDK
import { Polygon } from '@everstake/wallet-sdk';

// Hash transaction
const hash = '0x6a65103f50d40eb94b04fba1161e0dd44962f070bdcfc4c75b105ca37b2b08b2';
const status = await Polygon.isTransactionLoading(hash);
console.log(status); // return true or false until the transaction status is either succe

Sign Transaction

Securely sign Ethereum transactions using your own infrastructure with the assistance of our SDK. By signing transactions on your side, you maintain control over your private keys and sensitive data, enhancing the security of your operations. Our SDK simplifies the process, providing the necessary tools and functions to prepare, sign, and send transactions to the Ethereum network while ensuring that your private keys never leave your secure environment.

Signing on your side, Code Example

try {
    // import web3 lib
    import Web3 from "web3";
    const web3 = new Web3(RPC_URL);

    let result = null;
    await web3.eth.accounts.signTransaction(tx, privateKey).then(async (signedTx) => {
        result = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
    });
    return result; // Transaction result
} catch (error) {
    throw new Error(error);
}