> For the complete documentation index, see [llms.txt](https://docs.everstake.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.everstake.com/integrations/everstake-products/wallet-sdk/protocols/polygon-erc-20.md).

# Polygon (ERC-20)

Learn how to integrate Polygon staking into Everstake Wallet SDK.

## Getting Started <a href="#getting-started" id="getting-started"></a>

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](https://wallet-sdk-api.everstake.one/swagger/) with detailed examples

```hpkp
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 <a href="#step-1-installing-the-library" id="step-1-installing-the-library"></a>

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

{% tabs %}
{% tab title="npm" %}

```sh
$ npm install @everstake/wallet-sdk-polygon
```

{% endtab %}

{% tab title="yarn" %}

```sh
$ yarn add @everstake/wallet-sdk-polygon
```

{% endtab %}

{% tab title="pnpm" %}

```sh
$ pnpm add @everstake/wallet-sdk-polygon
```

{% endtab %}
{% endtabs %}

#### Step. 2: Import Wallet SDK <a href="#step-2-import-wallet-sdk" id="step-2-import-wallet-sdk"></a>

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

**Import ES6**

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

**Import ES5**

```typescript
// 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](https://github.com/everstake/wallet-sdk/issues).

## Stake <a href="#delegate-polygon" id="delegate-polygon"></a>

The <mark style="color:yellow;">`delegate`</mark> namespace contains methods used for sending transactions on delegation. The unique methods to the <mark style="color:yellow;">`delegate`</mark> namespace are:

* <mark style="color:yellow;">`approve(address, amount, isPOL = true)`</mark>: Approval of the amount for further debiting by a smart contract.
* <mark style="color:yellow;">`delegate(address, amount, isPOL = true)`</mark>: Delegate user tokens.

**Delegate Code Example**

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

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

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

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

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

## Undelegate

The <mark style="color:yellow;">`transaction`</mark> namespace contains methods used for sending transactions. The unique method to the <mark style="color:yellow;">`transaction`</mark> namespace is:

<mark style="color:yellow;">`undelegate(address, amount, isPOL = true)`</mark>: Undelegate user's tokens.

**Undelegate Code Example**

```typescript
// 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, true);
console.log(undelegateResp); // Raw Transaction
```

## Reward <a href="#claim-reward-polygon" id="claim-reward-polygon"></a>

The <mark style="color:yellow;">`transaction`</mark> namespace contains methods used for sending transactions. The unique method to the <mark style="color:yellow;">`transaction`</mark> namespace is:

<mark style="color:yellow;">`reward(address, isPOL = true)`</mark>: Reward user tokens (Claim reward).

**Claim Reward Code Example**

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

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

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

## Restake <a href="#restake-code-example" id="restake-code-example"></a>

The <mark style="color:yellow;">`transaction`</mark> namespace contains methods used for sending transactions. The unique method to the <mark style="color:yellow;">`transaction`</mark> namespace is:

<mark style="color:yellow;">`restake(address, isPOL = true)`</mark>: Restake user tokens (Claim reward and auto delegate them).

**Restake Code Example**

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

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

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

## Claim Undelegate <a href="#claim-undelegate-polygon" id="claim-undelegate-polygon"></a>

The <mark style="color:yellow;">`claimUndelegate`</mark> method uses for sending transaction on claim undelegation.

* <mark style="color:yellow;">`claimUndelegate(address, unbondNonce = 0, isPOL = true)`</mark>: Claim undelegation by address

**Claim Undelegate Example**

```typescript
// 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, true);
console.log(claim); // Raw Transaction Object
```

## Getting Info <a href="#getting-info-polygon" id="getting-info-polygon"></a>

The <mark style="color:yellow;">`get`</mark> namespace contains methods used for getting info. The unique methods to the `get` namespace are:

* <mark style="color:yellow;">`getReward(address)`</mark>: Gets the user's reward balance in tokens.
* <mark style="color:yellow;">`getTotalDelegate(address)`</mark>: Gets the user's delegate balance in tokens.
* <mark style="color:yellow;">`getUnbond(address)`</mark>: Gets the user's unbond balance in tokens.
* <mark style="color:yellow;">`getCurrentEpoch()`</mark>: Gets current epoch.
* <mark style="color:yellow;">`getBalanceOf(address, isPOL = true)`</mark>: Gets the user's balance
* <mark style="color:yellow;">`getUnbondNonces(address)`</mark>: Gets unbound nonce by address

**Getting Info Code Example**

```typescript
// 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) (POL)

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

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

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

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

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

## Loading Transaction <a href="#loading-transaction-polygon" id="loading-transaction-polygon"></a>

The <mark style="color:yellow;">`loading`</mark> namespace contains method used for getting info about loading transaction. The unique methods to the <mark style="color:yellow;">`loading`</mark> namespace is:

* <mark style="color:yellow;">`isTransactionLoading(hash)`</mark>: Waits for a transaction to be processed and returns the status of the transaction.

**Get Status Transaction**

```typescript
// 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 <a href="#sign-transaction-ethereum" id="sign-transaction-ethereum"></a>

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**

```typescript
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);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.everstake.com/integrations/everstake-products/wallet-sdk/protocols/polygon-erc-20.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
