> ## 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.

# TON

> Unified API + TON Integration Workflow

In the following guide, the integration process for the `ton_whales` chain is covered. The TON 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 TON-specific details**

  * `chain` — always set to `ton_whales` for TON-related requests.
  * `network` — environment in which the transaction is processed: `mainnet` or `testnet`.
  * `stakerAddress` — account address initiating staking, unstaking or withdrawal transactions.
  * `amount` — amount of tokens in nanoGRAMs (1 GRAM= 10⁹ nanoGRAMs).
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet for staking operations.
  * `publicKey` — public key of the nominator for the TON network.
</Note>

## Staking flow

### 1. Create staking request

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

Example request (for `mainnet` network):

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api-test.p2p.org/api/v1/unified/staking/stake \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "ton_whales",
      "network": "mainnet",
      "stakerAddress": "0QDLFn0rX92mwLFL5bMAkamPxvjM_2k4SHDi4VEQG4Jk8rCE",
  		"amount": "5000000000",
      "extra": {
          "publicKey": "dbc17009994431c741d22396f71ebb220951c2d2a643e0c17e63125d9acae32d",
          "walletVersion": "V3R1"
      }
  }'
  ```
</CodeGroup>

* `chain` — blockchain network, always set to `ton_whales` for TON-related requests.

* `network` — environment in which the transaction is processed: `mainnet` or `testnet`.

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

* `amount` — amount of tokens to stake in nanoGRAMs (1 GRAM = 10⁹ nanoGRAMs).

* `extra` — additional parameters:

  * `publicKey` — public key of the nominator for the TON network.
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "amount": "5000000000",
          "stakerAddress": "0QDLFn0rX92mwLFL5bMAkamPxvjM_2k4SHDi4VEQG4Jk8rCE",
          "unsignedTransactionData": "b5ee9c7241010201005c00011a29a9a3176761922b0000000f0301009462001b0eecbed3c3c21725606281a98dfb0152db86a09eb434df3d75fd862d8466e723b9aca00000000000000000000000000000da803efd00000193d519d3184773594005012a05f200a7846cb2",
          "extraData": {
              "seqno": 15,
              "walletVersion": "V3R1",
              "publicKey": "dbc17009994431c741d22396f71ebb220951c2d2a643e0c17e63125d9acae32d",
              "poolAddress": "kQA2Hdl9p4eELkrAxQNTG_YCpbcNQT1oab566_sMWwjNztst"
          }
      }
  }
  ```
</CodeGroup>

* `amount` — amount of tokens to stake in nanoGRAMs (1 GRAM= 10⁹ nanoGRAMs).

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

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

* `extraData` — additional transaction details:

  * `seqno` — [sequence number](https://docs.ton.org/v3/guidelines/smart-contracts/howto/wallet#replay-protection---seqno) of the message.
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.
  * `publicKey` — public key of the nominator for the TON network.
  * `poolAddress` — TON Whales pool address.

### 2. Sign and send transaction

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

To broadcast the signed transaction to the TON 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-test.p2p.org/api/v1/unified/transaction/broadcast \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "ton_whales",
      "network": "mainnet",
      "signedTransaction": "710f0456d675c0715bcdcbce5ab4fc5ad8e00cccaa3bd40fe59329cfe33c7089901bffa9c412bcd502c9f751f15de93abb297599c0dadb4f247eaeea72a2a003",
      "stakerAddress": "0QDLFn0rX92mwLFL5bMAkamPxvjM_2k4SHDi4VEQG4Jk8rCE",
      "extra": {
          "unsignedTransaction": "b5ee9c7241010201005a00011c29a9a317ffffffff00000000000301008d62001b0eecbed3c3c21725606281a98dfb0152db86a09eb434df3d75fd862d8466e7280d09dc3000000000000000000000000000007bcd1fef00000193e11e3d975012a05f2008b7558aef",
          "publicKey": "dbc17009994431c741d22396f71ebb220951c2d2a643e0c17e63125d9acae32d",
          "walletVersion": "V3R1"
      }
  }'
  ```
</CodeGroup>

* `chain` — blockchain network.

* `network` — environment in which the transaction is processed.

* `signedTransaction` — signed transaction in Base64 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:

  * `unsignedTransaction` — unsigned transaction in Base64 encrypted format.
  * `publicKey` — public key of the nominator for the TON network.
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "extraData": {
              "messageHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
          }
      }
  }
  ```
</CodeGroup>

* `messageHash`— hash of the transaction.

## Unstaking flow

### 1. Create withdrawal request

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

Example request (for `mainnet` network):

<CodeGroup>
  ```bash bash theme={null}
  curl --request POST \
       --url https://api-test.p2p.org/api/v1/unified/staking/withdraw \
       --header 'Content-Type: application/json' \
       --header 'Authorization: Bearer <token>' \
       --data '{
      "chain": "ton_whales",
      "network": "mainnet",
      "stakerAddress": "0QDLFn0rX92mwLFL5bMAkamPxvjM_2k4SHDi4VEQG4Jk8rCE",
      "extra": {
          "publicKey": "dbc17009994431c741d22396f71ebb220951c2d2a643e0c17e63125d9acae32d",
          "amount": "5000000000",
          "walletVersion": "V3R1"
      }
  }'
  ```
</CodeGroup>

* `chain` — blockchain network.

* `network` — environment in which the transaction is processed.

* `stakerAddress` — staking account address initiating the withdrawal transaction.

* `extra` — additional request parameters:

  * `publicKey` — public key of the nominator for the TON network.
  * `amount` — amount of tokens to withdraw in nanoGRAMs (1 GRAM = 10⁹ nanoGRAMs).
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.

Example response:

<CodeGroup>
  ```json JSON theme={null}
  {
      "error": null,
      "result": {
          "amount": "5000000000",
          "stakerAddress": "0QDLFn0rX92mwLFL5bMAkamPxvjM_2k4SHDi4VEQG4Jk8rCE",
          "unsignedTransactionData": "b5ee9c7241010201005c00011a29a9a3176761922b0000000f0301009462001b0eecbed3c3c21725606281a98dfb0152db86a09eb434df3d75fd862d8466e723b9aca00000000000000000000000000000da803efd00000193d519d3184773594005012a05f200a7846cb2",
          "extraData": {
              "seqno": 15,
              "walletVersion": "V3R1",
              "publicKey": "dbc17009994431c741d22396f71ebb220951c2d2a643e0c17e63125d9acae32d",
              "poolAddress": "kQA2Hdl9p4eELkrAxQNTG_YCpbcNQT1oab566_sMWwjNztst"
          }
      }
  }
  ```
</CodeGroup>

* `amount` — amount of tokens to withdraw in nanoGRAMs (1 GRAM = 10⁹ nanoGRAMs).

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

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

* `extraData` — additional transaction details:

  * `seqno` — [sequence number](https://docs.ton.org/v3/guidelines/smart-contracts/howto/wallet#replay-protection---seqno) of the message.
  * `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.
  * `publicKey` — public key of the nominator for the TON network.
  * `poolAddress` — TON Whales pool address.

### 2. Sign and send transaction

Use `unsignedTransactionData` to [sign and send](/docs/unified-api-signing-transaction) the transaction following the TON-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)
