Skip to main content
All CollectionsAPI
NEAR Protocol Staking API
NEAR Protocol Staking API
Allnodes Team avatar
Written by Allnodes Team
Updated over 2 years ago

The Allnodes API generates serialized unsigned transactions. To send a transaction to the network, you will need experience with near-api-js:

https://docs.near.org/tools/near-api-js/quick-reference

In every HTTP request of the Allnodes API, you need to specify your API key via an HTTP header: Authorization: Bearer <YOUR_API_KEY>


NEAR Protocol API documentation: https://docs.allnodes.com/near/staking


How to get an API key:

  1. Register an account here: https://www.allnodes.com

  2. Go to the settings of your account: https://www.allnodes.com/settings

  3. Open the API tab.

  4. Click on the "Enable API" button.

  5. Save the "Read and Write API Key" and "Read-Only API Key" in a safe place.


How to Stake

  1. You will need to prepare your wallet ID, validator ID and address with at least 1.1 NEAR.

  2. Send an HTTP POST request to the URL https://www.allnodes.com/api/v1/staking with the following json body:

    {
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "amount": "<NEAR_AMOUNT_TO_STAKE>",
    "currencySymbol": "NEAR",
    "action": "stake"
    }


    Example:

    curl --location --request POST 'https://www.allnodes.com/api/v1/staking' \
    --header 'Authorization: Bearer <YOUR_API_KEY>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "amount": "<NEAR_AMOUNT_TO_STAKE>",
    "currencySymbol": "NEAR",
    "action": "stake"
    }'


    The response to your request contains:

    • serializedTransaction - sign and send this transaction to the network using near-api-js.

  3. You successfully staked your coins!


How to Withdraw Your Stake

  1. You will first need to unbond your stake and wait for the unbonding period to finish (usually, it's about 2 days).
    Prepare your wallet ID and validator ID.

  2. To unbond your stake, send an HTTP POST request to the URL https://www.allnodes.com/api/v1/staking with the following json body:

    {
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "currencySymbol": "NEAR",
    "action": "unbond"
    }

    Example:

    curl --location --request POST 'https://www.allnodes.com/api/v1/staking' \
    --header 'Authorization: Bearer <YOUR_API_KEY>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "currencySymbol": "NEAR",
    "action": "unbond"
    }'

    The response to your request contains:

    • serializedTransaction - sign and send this transaction to the network using near-api-js.

  3. You successfully unbonded your stake! Now you need to wait 2 days before withdrawing your staked coins.

  4. Send an HTTP POST request to the URL https://www.allnodes.com/api/v1/staking with the following JSON body:

    {
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "currencySymbol": "NEAR",
    "action": "withdraw-stake"
    }

    Example:

    curl --location --request POST 'https://www.allnodes.com/api/v1/staking' \
    --header 'Authorization: Bearer <YOUR_API_KEY>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "accountID": "<YOUR_WALLET_ID>",
    "accountPublicKey": "<YOUR_PUBLIC_KEY>",
    "validatorID": "<VALIDATOR_ID>",
    "currencySymbol": "NEAR",
    "action": "withdraw-stake"
    }'

    The response to your request contains:

    • serializedTransaction - sign and send this transaction to the network using near-api-js.

  5. You have successfully withdrawn your staked coins!

Did this answer your question?