# NEAR Protocol Staking

Instructions: <https://help.allnodes.com/en/articles/6759442-near-protocol-staking-api>

## Stake coins

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

This endpoint allows you to get serialized unsigned transaction for staking 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 "NEAR"                                                                           |
| action<mark style="color:red;">\*</mark>           | string | Must be "stake"                                                                          |
| accountID<mark style="color:red;">\*</mark>        | string | You wallet ID (Example: "allnodes.near")                                                 |
| accountPublicKey<mark style="color:red;">\*</mark> | string | Your wallet public key (Example: "ed25519:1sTWdHCPJL3xkzxdg4ZkQm4d8A4TakDePXbpaGh4dAVE") |
| amount<mark style="color:red;">\*</mark>           | string | Amount to stake (in NEAR)                                                                |
| validatorID<mark style="color:red;">\*</mark>      | string | Validator ID to delegate (Example: "allnodes.poolv1.near")                               |

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

```javascript
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```javascript
{
  "error": "INVALID_ACCOUNT_ID"
}
```

{% 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 "NEAR"                                                                           |
| action<mark style="color:red;">\*</mark>           | string | Must be "unbond"                                                                         |
| accountID<mark style="color:red;">\*</mark>        | string | You wallet ID (Example: "allnodes.near")                                                 |
| accountPublicKey<mark style="color:red;">\*</mark> | string | Your wallet public key (Example: "ed25519:1sTWdHCPJL3xkzxdg4ZkQm4d8A4TakDePXbpaGh4dAVE") |
| validatorID<mark style="color:red;">\*</mark>      | string | Validator ID to unbond from (Example: "allnodes.poolv1.near")                            |

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

```javascript
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```javascript
{
  "error": "INVALID_VALIDATOR_ID"
}
```

{% 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**: 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 "NEAR"                                                                           |
| action<mark style="color:red;">\*</mark>           | string | Must be "withdraw-stake"                                                                 |
| accountID<mark style="color:red;">\*</mark>        | string | You wallet ID (Example: "allnodes.near")                                                 |
| accountPublicKey<mark style="color:red;">\*</mark> | string | Your wallet public key (Example: "ed25519:1sTWdHCPJL3xkzxdg4ZkQm4d8A4TakDePXbpaGh4dAVE") |
| validatorID<mark style="color:red;">\*</mark>      | string | Validator ID to withdraw stake from (Example: "allnodes.poolv1.near")                    |

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

```javascript
{
  serializedTransaction: string;
}
```

{% endtab %}

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

```javascript
{
  "error": "INVALID_PUBLIC_KEY"
}
```

{% endtab %}
{% endtabs %}
