> ## Documentation Index
> Fetch the complete documentation index at: https://docs.p2p.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Near

> Unified API + Near Integration Workflow

In the following guide, the integration process for the `near` chain is covered. The Near integration aligns with the general [Unified API process](/docs/unified-api-getting-started) but with network-specific parameters.

[Get an authentication token](/docs/authentication) to start using the Unified API.

Request examples are provided using [cURL](https://curl.se/).

> To check the integration guides for other chains, refer to the [Networks Supported](/docs/unified-api-networks) section.

<Note>
  **Key Near-specific details**

  * `chain` — always set to `near` for Near-related requests.
  * `network` — environment in which the transaction is processed: `mainnet` only.
  * `stakerAddress` — account address initiating staking, unstaking or withdrawal transactions.
  * `amount` — amount of tokens in NEAR.
</Note>

## Staking flow

### 1. Create staking request

Send a POST request to [/api/v1/unified/staking/stake](/reference/unified-create-stake-transaction).

Example request:

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/unified/staking/stake \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "near",
      "network": "mainnet",
      "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
      "amount": "1"
  }'
  ```
</CodeGroup>

* `chain` — blockchain network, always set to `near` for Near-related requests.
* `network` — environment in which the transaction is processed: `mainnet` only.
* `stakerAddress` — Near implicit account address initiating the staking transaction.
* `amount` — amount of tokens to stake in NEAR. Minimum amount is 1 NEAR.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "amount": 1,
          "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
          "unsignedTransactionData": "400000006339636434396461346662336361646535343264363235666139303961633434336537376131636231306530323837646636633562386466376534636330343000c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc0400f146f9cac7e0000130000007032702d6f72672e706f6f6c76312e6e6561723bf366edf6cf4e3890d95360b8fbc35cb7a2290076a0aa1224c256efbeb4caf30100000002110000006465706f7369745f616e645f7374616b65260000007b22616d6f756e74223a2231303030303030303030303030303030303030303030303030227d00203d88792d0000000000a1edccce1bc2d3000000000000",
          "createdAt": "2025-02-19T21:48:10.228Z",
          "extraData": {
              "transactionId": "548f7bce-6e03-411d-9118-2d59a021f177",
              "stakeId": "e0081662-8a9c-47b5-9c26-45320b8ce951",
              "gasEstimate": {
                  "amount": "0.025000000000000000",
                  "gasLimit": "50000000000000"
              }
          }
      }
  }
  ```
</CodeGroup>

* `amount` — amount of tokens to stake in NEAR.

* `stakerAddress` — staking account address receiving the staked tokens.

* `unsignedTransactionData` — unsigned transaction in hexadecimal (hex) encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.

* `createdAt` — timestamp of the transaction in the ISO 8601 format.

* `extraData` — additional transaction details:

  * `transactionId` — unique identifier of the transaction within this staking session.

  * `stakeId` — unique identifier for the staking request.

  * `gasEstimate` — estimated gas usage details:

    * `amount` — estimated transaction fee in NEAR.
    * `gasLimit` — maximum gas limit for processing the transaction in yoctoNEAR (1 NEAR = 10¹⁸ yoctoNEAR).

### 2. Sign and send transaction

Use `unsignedTransactionData` to [sign](/docs/unified-api-signing-transaction) the transaction.

To broadcast the signed transaction to the Near network, send a POST request to [/api/v1/unified/transaction/broadcast](/reference/unified-transaction-send).

Example request:

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/unified/transaction/broadcast \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "near",
      "network": "mainnet",
      "signedTransaction": "400000006339636434396461346662336361646535343264363235666139303961633434336537376131636231306530323837646636633562386466376534636330343000c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc04012146f9cac7e0000130000007032702d6f72672e706f6f6c76312e6e6561728c7d5ee5f77c298039c9ccd944ebb6218a7a036737c12356e75ef912662509870100000002110000006465706f7369745f616e645f7374616b65260000007b22616d6f756e74223a2231303030303030303030303030303030303030303030303030227d00203d88792d0000000000a1edccce1bc2d300000000000000ebc276fccd41088080c127999bd78cc5ecfbb8ce6282638b5cd19e3f465bd402c8cf30f8e5b4aa4fccae9f81d8340862d4748b102e4e2621533e9f788a793705",
      "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
      "extra": {
          "transactionId": "548f7bce-6e03-411d-9118-2d59a021f177"
      }
  }'
  ```
</CodeGroup>

* `chain` — blockchain network.
* `network` — environment in which the transaction is processed.
* `signedTransaction` — signed transaction in hexadecimal (hex) encrypted format, which contains all transaction details (e.g., accounts, instructions, and signatures) required to broadcast the transaction to the network.
* `stakerAddress` — staking account address receiving the staked tokens.
* `extra` — additional parameters:
  * `transactionId` — unique identifier of the staking transaction, obtained from the previous step.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "extraData": {
              "transactionHash": "HvnL1nyej4cCJnUbeghqWdxeVFkXdDjroA4yN6zcHv9f"
          }
      }
  }
  ```
</CodeGroup>

* `extraData` — additional transaction details:
  * `transactionHash` — hash of the block in which the transaction has been included.

## Unstaking flow

### 1. Create unstaking request

Send a POST request to [/api/v1/unified/staking/unstake](/reference/unified-create-unstake-transaction).

Example request:

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/unified/staking/unstake \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "near",
      "network": "mainnet",
      "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
      "extra": {
          "amount": "1"
      }
  }'
  ```
</CodeGroup>

* `chain` — blockchain network.
* `network` — environment in which the transaction is processed.
* `stakerAddress` — account address initiated the staking transaction.
* `extra` — additional parameters:
  * `amount` — amount of tokens to withdraw in NEAR.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "amount": "1",
          "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
          "unsignedTransactionData": "400000006339636434396461346662336361646535343264363235666139303961633434336537376131636231306530323837646636633562386466376534636330343000c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc0400b146f9cac7e0000130000007032702d6f72672e706f6f6c76312e6e656172afa6fb301707310d7c898f7c9f83fc8bc91be960e3a286145afe416f8c418942010000000207000000756e7374616b65260000007b22616d6f756e74223a2231303030303030303030303030303030303030303030303030227d00203d88792d000000000000000000000000000000000000",
          "createdAt": "2025-02-10T22:36:14.547Z",
          "extraData": {
              "transactionId": "69f8b6f1-8b36-4429-843c-90107cfb5bfb",
              "stakeId": "6f102d59-b479-4a87-905b-7572b904bb01",
              "gasEstimate": {
                  "amount": "0.025000000000000000",
                  "gasLimit": "50000000000000"
              }
          }
      }
  }
  ```
</CodeGroup>

* `amount` — amount of tokens to withdraw in NEAR.

* `stakerAddress` — account address initiated the staking transaction.

* `unsignedTransactionData` — unsigned transaction in hexadecimal (hex) encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.

* `createdAt` — timestamp of the transaction in the ISO 8601 format.

* `extraData` — additional transaction details:

  * `transactionId` — unique identifier of the transaction within this withdrawal session.

  * `stakeId` — unique identifier of the withdrawal request.

  * `gasEstimate` — estimated gas usage details:

    * `amount` — estimated transaction fee in NEAR.
    * `gasLimit` — maximum gas limit for processing the transaction in yoctoNEAR (1 NEAR = 10¹⁸ yoctoNEAR).

### 2. Sign and send transaction

Use `unsignedTransactionData` to [sign and send](/docs/unified-api-signing-transaction) the transaction following the Near-specific signing logic.

### 3. Create withdrawal request

<Note>
  Note that the withdrawal is available only after the unstaking period, which lasts for 4 epochs (\~72 hours).
</Note>

Send a POST request to [/api/v1/unified/staking/withdraw](/reference/unified-create-withdraw-transaction).

Example request:

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/unified/staking/withdraw \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "near",
      "network": "mainnet",
      "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040"
  }'
  ```
</CodeGroup>

* `chain` — blockchain network.
* `network` — environment in which the transaction is processed.
* `stakerAddress` — account address initiating the withdrawal transaction.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "amount": "1",
          "stakerAddress": "c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc040",
          "unsignedTransactionData": "400000006339636434396461346662336361646535343264363235666139303961633434336537376131636231306530323837646636633562386466376534636330343000c9cd49da4fb3cade542d625fa909ac443e77a1cb10e0287df6c5b8df7e4cc0400b146f9cac7e0000130000007032702d6f72672e706f6f6c76312e6e656172afa6fb301707310d7c898f7c9f83fc8bc91be960e3a286145afe416f8c418942010000000207000000756e7374616b65260000007b22616d6f756e74223a2231303030303030303030303030303030303030303030303030227d00203d88792d000000000000000000000000000000000000",
          "createdAt": "2025-02-10T22:36:14.547Z",
          "extraData": {
              "transactionId": "69f8b6f1-8b36-4429-843c-90107cfb5bfb",
              "stakeId": "6f102d59-b479-4a87-905b-7572b904bb01",
              "gasEstimate": {
                  "amount": "0.025000000000000000",
                  "gasLimit": "50000000000000"
              }
          }
      }
  }
  ```
</CodeGroup>

* `amount` — amount of tokens to withdraw in NEAR.

* `stakerAddress` — account address initiated the withdrawal transaction.

* `unsignedTransactionData` — unsigned transaction in hexadecimal (hex) encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.

* `createdAt` — timestamp of the transaction in the ISO 8601 format.

* `extraData` — additional transaction details:

  * `transactionId` — unique identifier of the transaction within this withdrawal session.

  * `stakeId` — unique identifier of the withdrawal request.

  * `gasEstimate` — estimated gas usage details:

    * `amount` — estimated transaction fee in NEAR.
    * `gasLimit` — maximum gas limit for processing the transaction in yoctoNEAR (1 NEAR = 10¹⁸ yoctoNEAR).

### 4. Sign and send transaction

Use `unsignedTransactionData` to [sign and send](/docs/unified-api-signing-transaction) the transaction following the Near-specific signing logic.


## Related topics

- [Unified API Reference](/reference/unified-create-stake-transaction.md)
- [Integration Workflow Example](/docs/unified-api-getting-started.md)
- [Networks Supported](/docs/unified-api-networks.md)
