# Solana Staking

Instructions: <https://help.allnodes.com/en/articles/6612209-solana-staking-api>

## Get stake accounts

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

This endpoint allows you to get list of all your stake accounts.

#### 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 "SOL"                |
| action<mark style="color:red;">\*</mark>         | string | Must be "get-stake-accounts" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address          |

{% tabs %}
{% tab title="200: OK " %}

```javascript
[
  {
    publicKey: string;
    rentEpoch: number;
    lamports: number;
    stake: number;
    validatorPublicKey: string | null;
    status: {
      active: number;
      inactive: number;
      state: 'active' | 'inactive' | 'activating' | 'deactivating';
    };
  }
]
```

{% endtab %}
{% endtabs %}

## Create stake account

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

This endpoint allows you to get serialized unsigned transaction for creating stake account.

#### 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 "SOL"                  |
| action<mark style="color:red;">\*</mark>         | string | Must be "create-stake-account" |
| address<mark style="color:red;">\*</mark>        | string | Your wallet address            |
| amount<mark style="color:red;">\*</mark>         | string | Amount to stake                |

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

```json
{
  network: string;
  amount: string;
  serializedTransaction: string;
  stakeAccountSecretKey: string;
  stakeAccountPublicKey: string;
}
```

{% endtab %}

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

```json
{
  "error": "ACCOUNT_DOES_NOT_EXIST"
}
```

{% endtab %}
{% endtabs %}

## 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 delegating staked coins 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 "SOL"                                                                                  |
| action<mark style="color:red;">\*</mark>                | string | Must be "stake"                                                                                |
| address<mark style="color:red;">\*</mark>               | string | Your wallet address                                                                            |
| stakeAccountPublicKey<mark style="color:red;">\*</mark> | string | Public key of your stake account. Public key can be extracted from "Create stake account" call |

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

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

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

## Unbond coins

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

This endpoint allows you to get serialized unsigned transaction for unbonding coins (deactivating your stake account).

#### 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 "SOL"                                                                                  |
| action<mark style="color:red;">\*</mark>                | string | Must be "unbond-stake"                                                                         |
| address<mark style="color:red;">\*</mark>               | string | Your wallet address                                                                            |
| stakeAccountPublicKey<mark style="color:red;">\*</mark> | string | Public key of your stake account. Public key can be extracted from "Create stake account" call |

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

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

{% endtab %}

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

```javascript
{
  "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 serialized unsigned transaction for withdraw stake.

#### 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 "SOL"                                                                                  |
| action<mark style="color:red;">\*</mark>                | string | Must be "withdraw-stake"                                                                       |
| address<mark style="color:red;">\*</mark>               | string | Your wallet address                                                                            |
| stakeAccountPublicKey<mark style="color:red;">\*</mark> | string | Public key of your stake account. Public key can be extracted from "Create stake account" call |
| amount<mark style="color:red;">\*</mark>                | string | Amount to withdraw                                                                             |

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

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

{% endtab %}

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

```javascript
{
  "error": "NOT_SPECIFIED_AMOUNT"
}
```

{% endtab %}
{% endtabs %}
