# Polkadot Staking

Instructions: <https://help.allnodes.com/en/articles/6730085-polkadot-staking-api>

## Bond coins (initial)

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

This endpoint allows you to get serialized unsigned transaction for initial bond coins.

#### 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 "DOT"                                            |
| action<mark style="color:red;">\*</mark>         | string | Must be "initial-bond"                                   |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address (will be used as stash account)      |
| controller<mark style="color:red;">\*</mark>     | string | Your wallet address (will be used as controller account) |
| payee<mark style="color:red;">\*</mark>          | string | "stash-reinvest" \| "stash-save" \| "controller"         |
| amount<mark style="color:red;">\*</mark>         | string | Amount to stake (in DOT)                                 |

{% tabs %}
{% tab title="200: OK Serialized transaction successfully generated." %}

```json
{
  serializedTransaction: string;
}
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

## Bond extra coins

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

This endpoint allows you to get serialized unsigned transaction for bonding extra coins.

#### 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 "DOT"                       |
| action<mark style="color:red;">\*</mark>         | string | Must be "bond-extra"                |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address (stash account) |
| amount<mark style="color:red;">\*</mark>         | string | Amount to bond (in DOT)             |

{% tabs %}
{% tab title="200: OK Serialized transaction successfully generated." %}

```json
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```json
{
  "error": "INVALID_AMOUNT"
}
```

{% endtab %}
{% endtabs %}

## Nominate validators

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

This endpoint allows you to get serialized unsigned transaction for nominate validators.

#### 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 "DOT"                                                   |
| action<mark style="color:red;">\*</mark>         | string    | Must be "nominate"                                              |
| address<mark style="color:red;">\*</mark>        | string    | Your wallet address (stash account)                             |
| validators<mark style="color:red;">\*</mark>     | string\[] | Addresses of validators to nominate (up to 16 unique addresses) |

{% tabs %}
{% tab title="200: OK Serialized transaction successfully generated." %}

```json
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```json
{
  "error": "VALIDATORS_UNIQ_ERROR"
}
```

{% endtab %}
{% endtabs %}

## Unbond coins

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

This endpoint allows you to get serialized unsigned transaction for unbonding coins.

#### 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 "DOT"                       |
| action<mark style="color:red;">\*</mark>         | string | Must be "unbond"                    |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address (stash account) |
| amount<mark style="color:red;">\*</mark>         | string | Amount to unbond (in DOT)           |

{% tabs %}
{% tab title="200: OK Serialized transaction successfully generated." %}

```json
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```javascript
{
  "error": "NOT_ENOUGH_AMOUNT"
}
```

{% 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 serialized unsigned transaction for withdraw stake.\
\
**Unbonding period**: 28 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 "DOT"                       |
| action<mark style="color:red;">\*</mark>         | string | Must be "withdraw-stake"            |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address (stash account) |

{% tabs %}
{% tab title="200: OK Serialized transaction successfully generated." %}

```json
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```json
{
  "error": "INVALID_ERA_FOR_WITHDRAW"
}
```

{% endtab %}
{% endtabs %}
