# Staking

## Approve a token

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for approve tokens.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description         |
| ------------------------------------------------ | ------ | ------------------- |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"       |
| action<mark style="color:red;">\*</mark>         | string | Must be "approve"   |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "TOKEN_ALREADY_APPROVED"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}

## Stake coins/tokens

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for staking coins/tokens to Allnodes validator.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description         |
| ------------------------------------------------ | ------ | ------------------- |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"       |
| action<mark style="color:red;">\*</mark>         | string | Must be "stake"     |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address |
| amount<mark style="color:red;">\*</mark>         | string | Amount to delegate  |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "NOT_ENOUGH_TOKENS"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}

## Withdraw rewards

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for withdraw rewards earned.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description                |
| ------------------------------------------------ | ------ | -------------------------- |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"              |
| action<mark style="color:red;">\*</mark>         | string | Must be "withdraw-rewards" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address        |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "NOT_ENOUGH_REWARDS"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}

## Restake rewards

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for restake rewards earned.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description               |
| ------------------------------------------------ | ------ | ------------------------- |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"             |
| action<mark style="color:red;">\*</mark>         | string | Must be "restake-rewards" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address       |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "NOT_ENOUGH_REWARDS"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}

## Unbond coins/tokens

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for unbonding coins/tokens from Allnodes validator.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description            |
| ------------------------------------------------ | ------ | ---------------------- |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"          |
| action<mark style="color:red;">\*</mark>         | string | Must be "unbond-stake" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address    |
| amount<mark style="color:red;">\*</mark>         | string | Amount to undelegate   |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "NOT_ENOUGH_TOKENS"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}

## Withdraw stake (after unbonding period finished)

<mark style="color:green;">`POST`</mark> `https://www.allnodes.com/api/v1/staking`

This endpoint allows you to get transaction params for withdraw stake from Allnodes validator. \
\
**Unbonding period**: 80 checkpoints (1.5 - 2 days)

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer TOKEN |

#### Request Body

| Name                                             | Type   | Description              |
| ------------------------------------------------ | ------ | ------------------------ |
| currencySymbol<mark style="color:red;">\*</mark> | string | Must be "POL"            |
| action<mark style="color:red;">\*</mark>         | string | Must be "withdraw-stake" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address      |
| amount<mark style="color:red;">\*</mark>         | string | Amount to withdraw       |

{% tabs %}
{% tab title="200 Transaction params successfully generated." %}

```
{
  network: string;
  toAddress: string;
  amount: string;
  gasLimit: number;
  gasPrice: number;
  data: string;
}
```

{% endtab %}

{% tab title="400 Example of error response." %}

```
{
  "error": "NOT_ENOUGH_EPOCHS_PASSED"
}
```

{% endtab %}

{% tab title="404 Example of error response." %}

```
{
  "error": "INVALID_ADDRESS"
}
```

{% endtab %}
{% endtabs %}
