Babylon

Unified API + Babylon Integration Workflow

In the following guide, the integration process for the babylon-btc chain and testnet network is covered. The Babylon integration aligns with the general Unified API process but with network-specific parameters.

Get an authentication token to start using the Unified API.

Request examples are provided using cURL.

To check the integration guides for other chains, refer to the Networks section.

📘

Key Babylon-specific details

  • chain — always set to babylon-btc for Babylon-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 sats, min amount is 1.

Staking Flow

1. Create Staking Request

Send a POST request to /api/v1/unified/staking/stake.

Example request (for mainnet network):

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": "babylon-btc",
    "network": "testnet",
    "stakerAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs",
    "amount": "1",
    "extra": {
      "stakerPublicKey": "0384b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98"
    }
}'

Example response:

{
    "error": null,
    "result": {
        "stakerAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs",
        "unsignedTransactionData": "70736274ff0100db0200000001d234d43d0f49b02eeb06dce44a2bf0ebfada6915d8d933f9d73514d87c6c278a0200000000fdffffff0340420f000000000022512080626985aa1791ea5c368e9c595904d7a5669084172a3be41932716bf9e086df0000000000000000496a47626264340084b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c984bf609ba8977d3fbf4dee7f9d993c41f2fa584ccd27b3e4bf04a5376267e13c000969cfc1d0000000000225120eac91baeaabcbd5fa41ed3cecd72fbf8c9a24eb709b29ec55cc0082fb45d00ed000000000001012be73f2d0000000000225120eac91baeaabcbd5fa41ed3cecd72fbf8c9a24eb709b29ec55cc0082fb45d00ed01172084b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c9800000000",
        "extraData": {
            "stakerPublicKey": "84b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98",
            "stakeAmount": 1000000,
            "stakingDuration": 150,
            "fee": 267,
            "finallyProviderPublicKey": "4bf609ba8977d3fbf4dee7f9d993c41f2fa584ccd27b3e4bf04a5376267e13c0"
        }
    }
}

2. Sign and Send Transaction

Use unsignedTransactionData to sign the transaction.

To broadcast the signed transaction to the Babylon network, send a POST request to /api/v1/unified/transaction/broadcast.

Example request:

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": "babylon-btc",
    "network": "testnet",
    "stakerAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs",
    "signedTransaction":    "02000000000101c3898f041f0984eec6191f1aa8e34630dba7693e0cac897b7a636cdd897939470200000000fdffffff037176000000000000225120c999af7219b587edcbd0495446c75cdf61abc4a8415a3b2e4b1270e8e40ae3d00000000000000000496a47626264340084b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c984bf609ba8977d3fbf4dee7f9d993c41f2fa584ccd27b3e4bf04a5376267e13c0009f9d03e10500000000225120eac91baeaabcbd5fa41ed3cecd72fbf8c9a24eb709b29ec55cc0082fb45d00ed01404534873265173f212b4d74e8aa038cd7d08b7f8d836e450a8ddb0698fdd7436686cdbaf826ddbe6d6c21be14e65bf7a87b12aa0efb24e38846ec2d02602dcb8c00000000"
}'

Example response:

{
    "error": null,
    "result": {
        "extraData": {
            "transactionHash": "5bc762103a40f102899b4f06af266fe9047ce824024ef25a5b048b854ddec858"
        }
    }
}

Unstaking Flow

1. Create Unstaking Request

Send a POST request to /api/v1/unified/staking/unstake.

Example request:

curl --request POST \
     --url https://api-test.p2p.org/api/v1/unified/staking/unstake \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <token>' \
     --data '{
    "chain": "babylon-btc",
    "network": "testnet",
    "stakerAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs"
    "extra": {
        "stakerPublicKey": "0384b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98",
        "stakeTransactionHash": "f1b05868cf4f6a43c5d3f89dab36b2f9556b24bd55f66436c8594fb5d693c4e6"
    }
}'

Example response:

{
    "error": null,
    "result": {
        "extraData": {
            "stakerPublicKey": "84b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98",
            "stakeTransactionHash": "5bc762103a40f102899b4f06af266fe9047ce824024ef25a5b048b854ddec858",
            "unstakeTransactionHex": "70736274ff01005e020000000158c8de4d858b045b5af24e0224e87c04e96f26af064f9b8902f1403a1062c75b0000000000ffffffff0188360f000000000022512013edabd9b2c7d91d967bcf2bcd8289b821d4cc894738eefeb08ac49af9400ff7000000000001012b40420f000000000022512080626985aa1791ea5c368e9c595904d7a5669084172a3be41932716bf9e086df6215c150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0a975832ad515ff03b76ce8bb0d40d077cba912fa1da48dce220061f060bea4ee7ef97a6d24c34584e32c874bd3fe429c1319758201d6989b8e1b6de6411fea468b2084b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98ad2017921cf156ccb4e73d428f996ed11b245313e37e27c978ac4d2cc21eca4672e4ac2049766ccd9e3cd94343e2040474a77fb37cdfd30530d05f9f1e96ae1e2102c86eba2076d1ae01f8fb6bf30108731c884cddcf57ef6eef2d9d9559e130894e0e40c62cba529cc001172050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac00000",
            "unstakeFee": 3000
        }
    }
}

2. Sign and Send Transaction

Use unsignedTransactionData to sign and send the transaction following the Babylon-specific signing logic.

3. Create Withdrawal Request

📘

Note that the withdrawal is available after ~28 days after unstaking.

Send a POST request to /api/v1/unified/staking/withdraw.

Example request:

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": "babylon-btc",
    "network": "testnet",
    "stakerAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs",
    "amount": "1002282880",
    "extra": {
        "stakerPublicKey": "0384b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98",
        "stakeTransactionHash": "f1b05868cf4f6a43c5d3f89dab36b2f9556b24bd55f66436c8594fb5d693c4e6"
    }
}'

Example response:

{
    "error": null,
    "result": {
        "extraData": {
            "withdrawalAddress": "tb1paty3ht42hj74lfq7608v6uhmlry6yn4hpxefa32ucqyzldzaqrks3juxrs",
            "stakerPublicKey": "84b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98",
            "stakeTransactionHash": "df5c7c052e953ea7697f0df6452b40f4d79e5a47eb062f483db7f9aff13cc11c",
            "withdrawalTransactionHex": "70736274ff01005e02000000016a10981a428a4c21ff41cd531305497abd4dfc4101e669687aa082714080f16d00000000000500000001e9350f0000000000225120eac91baeaabcbd5fa41ed3cecd72fbf8c9a24eb709b29ec55cc0082fb45d00ed000000000001012b88360f000000000022512013edabd9b2c7d91d967bcf2bcd8289b821d4cc894738eefeb08ac49af9400ff74215c150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac07ef97a6d24c34584e32c874bd3fe429c1319758201d6989b8e1b6de6411fea46252084b203765094496a32cf8817fba045d0bc8a4dab3256551c41f05a8536141c98ad55b2c001172050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac00000",
            "fee": 159
        }
    }
}

4. Sign and Send Transaction

Use unsignedTransactionData to sign and send the transaction following the Babylon-specific signing logic.

What's Next?