dYdX

Unified API + dYdX Integration Workflow

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

  • chain — always set to dydx for dYdX-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 dYdX.
  • extra.additionalAddresses.cosmosPubKey— staker public key; required only for new accounts that have not performed any transactions before.

Staking Flow

1. Create Staking Request

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

Example request (for already existing account):

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": "dydx",
    "network": "mainnet",
    "stakerAddress": "dydx1tmpp633vf37d67lqnyuxw5a8lvvdaqks5kgtah",
    "amount": 0.8
}'
  • chain — blockchain network, always set to dydx for dYdX-related requests.
  • network — environment in which the transaction is processed (mainnet only).
  • stakerAddress — dYdX implicit account address initiating the staking transaction.
  • amount — amount of tokens to stake in dYdX.

Example request (for a new account):

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": "dydx",
    "network": "mainnet",
    "stakerAddress": "dydx1pq0w7wedwvgttv4zjr99kx6n6e8ennu9c7nh5x",
    "amount": 0.8,
    "extra": {
        "additionalAddresses": {
            "cosmosPubKey": "ApmGOJAE6bgmNgawUZa8HA3mGNFehOl69Dst89kHqU5V"
        }
    }
}'
  • chain — blockchain network, always set to dydx for dYdX-related requests.
  • network — environment in which the transaction is processed (mainnet only).
  • stakerAddress — dYdX implicit account address initiated the staking transaction.
  • amount — amount of tokens to stake in dYdX.
  • extra — additional request parameters:
    • extra.additionalAddresses.cosmosPubKey — staker public key; required for new accounts only.

Example response:

{
  "error": null,
  "result": {
    "amount": 2,
    "stakerAddress": "dydx1tmpp633vf37d67lqnyuxw5a8lvvdaqks5kgtah",
    "unsignedTransactionData": "<Base64 unsigned tx>",
    "createdAt": "2025-04-14T11:13:32.812Z",
    "extraData": {
      "transactionId": "dea742b5-bd89-4ddf-aa69-dbbf65edb2f0",
      "stakeId": "6c058ca1-75af-448c-8db4-bae6c4ea9636",
      "gasEstimate": {
        "amount": "0.001992075000000000",
        "gasLimit": "159366"
      }
    }
  }
}
  • amount — amount of tokens to stake in dYdX.
  • 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.
  • 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 dYdX.
      • gasLimit — maximum gas limit estimated for the transaction.

2. Sign and Send Transaction

Use unsignedTransactionData to sign the transaction.

To broadcast the signed transaction to the dYdX 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": "dydx",
    "network": "mainnet",
    "signedTransaction": "<signed_transaction>",
    "stakerAddress": "dydx1tmpp633vf37d67lqnyuxw5a8lvvdaqks5kgtah",
    "extra": {
        "transactionId": "dea742b5-bd89-4ddf-aa69-dbbf65edb2f0"
    }
}'
  • 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 request parameters:
    • transactionId — unique identifier of the staking transaction.

Example response:

{
  "error": null,
  "result": {
    "extraData": {
      "transactionHash": "<transaction_hash>"
    }
  }
}
  • 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.

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": "dydx",
    "network": "mainnet",
    "stakerAddress": "dydx1pq0w7wedwvgttv4zjr99kx6n6e8ennu9c7nh5x",
    "extra": {
        "amount": 0.8
    }
}'
  • chain — blockchain network.
  • network — environment in which the transaction is processed.
  • stakerAddress — account address initiated the staking transaction.
  • extra — additional request parameters:
    • amount — amount of tokens to withdraw in dYdX.

Example response:

{
  "error": null,
  "result": {
    "amount": 0.8,
    "stakerAddress": "dydx1pq0w7wedwvgttv4zjr99kx6n6e8ennu9c7nh5x",
    "unsignedTransactionData": "<Base64 unsigned tx>",
    "createdAt": "2025-04-14T12:54:33.472Z",
    "extraData": {
      "transactionId": "2b185ae0-a97d-4088-9ed0-38b533943fe2",
      "stakeId": "9b7114f4-40c1-4c78-984f-1fdffdbe98ac",
      "gasEstimate": {
        "amount": "0.0024585",
        "gasLimit": "196680"
      }
    }
  }
}
  • amount — amount of tokens to withdraw in dYdX.
  • stakerAddress — account address initiated the staking transaction.
  • unsignedTransactionData — unsigned transaction in Base64 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 dYdX.
      • gasLimit — maximum gas limit estimated for the transaction.

2. Sign and Send Transaction

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

3. Create Withdrawal Request

📘

Note that the withdrawal is available only after the 30-day unbonding period.

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": "dydx",
    "network": "mainnet",
    "stakerAddress": "dydx1pq0w7wedwvgttv4zjr99kx6n6e8ennu9c7nh5x"
}'
  • chain — blockchain network.
  • network — environment in which the transaction is processed.
  • stakerAddress — account address initiating the withdrawal transaction.

Example response:

{
  "error": null,
  "result": {
    "extraData": {
      "transactionHash": "834059BE0B72D95F2702DBB082D90F9858A5D71694B772D968390604E518A919"
    }
  }
}
  • amount — amount of tokens to withdraw in dYdX.
  • stakerAddress — account address initiated the withdrawal transaction.
  • unsignedTransactionData — unsigned transaction in Base64 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 dYdX.
      • gasLimit — maximum gas limit estimated for the transaction.

4. Sign and Send Transaction

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

What's Next?