Cosmos

Unified API + Cosmos Integration Workflow

In the following guide, the integration process for the cosmos chain is covered. The Cosmos 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 Cosmos-specific details

  • chain — always set to cosmos for Cosmos-related requests.
  • network — environment in which the transaction is processed (cosmoshub-4).
  • stakerAddress — account address initiating staking, unstaking or withdrawal transactions.
  • amount — token amount in ATOM (in uatom internally).

Staking Flow

1. Create Stake Request

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

Example request (for cosmoshub-4 network):

curl --request POST \
     --url https://api.p2p.org/api/v1/unified/staking/stake \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <token>' \
     --data '{
    "chain": "cosmos",
    "network": "cosmoshub-4",
    "stakerAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
    "amount": "0.0042"
}'

Example response:

{
  "error": null,
  "result": {
    "amount": 0.0042,
    "stakerAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
    "unsignedTransactionData": {
      "messages": [
        {
          "typeUrl": "/cosmos.staking.v1beta1.MsgUndelegate",
          "value": {
            "delegatorAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
            "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
            "amount": {
              "denom": "uatom",
              "amount": "4000"
            }
          }
        }
      ],
      "fee": {
        "amount": [
          {
            "amount": "14672",
            "denom": "uatom"
          }
        ],
        "gas": "586847"
      },
      "memo": "",
      "encodedBody": "0a9d010a252f636f736d6f732e7374616b696e672e763162657461312e4d7367556e64656c656761746512740a2d636f736d6f7331746d7070363333766633376436376c716e797578773561386c76766461716b736130783061711234636f736d6f7376616c6f7065723133326a757a6b3067646d77757876783470687567376d33796d796174786c68393733346734771a0d0a057561746f6d120434303030",
      "encodedAuthInfo": "0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21030b155e1a5773bfae8759223f986febc4094328de05f79924363cc6887ffd9aed12040a020801180212140a0e0a057561746f6d1205313436373210dfe823",
      "messageHash": "cd63647dbc65aaae6a6fd925df121ffde799eadb665784a3a465993207024ec5"
    },
    "createdAt": "2025-03-31T08:02:36.633Z",
    "extraData": {
      "currency": "atom",
      "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
      "rewardDestinationAddress": "cosmos1k664uhuyzpwss3y45fc0zzamcr3ujpeww33ruu"
    }
  }
}

2. Sign and Send Transaction

Use unsignedTransactionData to sign the transaction using the Cosmos-specific signing logic.

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

Example request:

curl --request POST \
     --url https://api.p2p.org/api/v1/unified/transaction/broadcast \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <token>' \
     --data '{
    "chain": "cosmos",
    "network": "cosmoshub-4",
    "stakerAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
    "signedTransaction": "0aa6010aa3010a252f636f736d6f732e7374616b696e672e763162657461312e4d7367556e64656c6567617465127a0a2f63656c657374696131746d7070363333766633376436376c716e797578773561386c76766461716b737639686c3864123663656c657374696176616c6f70657231616d6d30756d7871787877386a32713630783738787333327330383936303673646d767839321a0f0a047574696112073130303030303012660a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21030b155e1a5773bfae8759223f986febc4094328de05f79924363cc6887ffd9aed12040a020801180112120a0c0a047574696112043439363010f08d0c1a40b704538dadc6a1de4d7c881a1454ca75245f2651b35347062b9246543d2f7eb016bc897eeeeac37702ddaf6697d92b75cd659b4be46103a6da0cf3407dc0d73b"
}'

Unstaking Flow

1. Create Unstaking Request

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

Example request:

curl --request POST \
     --url https://api.p2p.org/api/v1/unified/staking/unstake \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <token>' \
     --data '{
    "chain": "cosmos",
    "network": "cosmoshub-4",
    "stakerAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
    "extra": {
        "amount": 0.0042
    }
}'

Example response:

{
  "error": null,
  "result": {
    "amount": 0.0042,
    "stakerAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
    "unsignedTransactionData": {
      "messages": [
        {
          "typeUrl": "/cosmos.staking.v1beta1.MsgUndelegate",
          "value": {
            "delegatorAddress": "cosmos1tmpp633vf37d67lqnyuxw5a8lvvdaqksa0x0aq",
            "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
            "amount": {
              "denom": "uatom",
              "amount": "4000"
            }
          }
        }
      ],
      "fee": {
        "amount": [
          {
            "amount": "14672",
            "denom": "uatom"
          }
        ],
        "gas": "586847"
      },
      "memo": "",
      "encodedBody": "0a9d010a252f636f736d6f732e7374616b696e672e763162657461312e4d7367556e64656c656761746512740a2d636f736d6f7331746d7070363333766633376436376c716e797578773561386c76766461716b736130783061711234636f736d6f7376616c6f7065723133326a757a6b3067646d77757876783470687567376d33796d796174786c68393733346734771a0d0a057561746f6d120434303030",
      "encodedAuthInfo": "0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21030b155e1a5773bfae8759223f986febc4094328de05f79924363cc6887ffd9aed12040a020801180212140a0e0a057561746f6d1205313436373210dfe823",
      "messageHash": "cd63647dbc65aaae6a6fd925df121ffde799eadb665784a3a465993207024ec5"
    },
    "createdAt": "2025-03-27T07:16:58.337Z",
    "extraData": {
      "currency": "atom",
      "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
      "rewardDestinationAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r"
    }
  }
}

2. Sign and Send Transaction

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

What's Next?