Get Transaction Status for Single-Chain Swaps

ยท

Learn how to retrieve the final transaction status of a single-chain swap using transaction hash (txhash) via OKX DEX API.

API Endpoint

GET https://web3.okx.com/api/v5/dex/aggregator/history

Request Parameters

ParameterTypeRequiredDescription
chainIndexStringYesUnique chain identifier (e.g., 1 for Ethereum). Supported chains
chainIdStringYes(Deprecated) Alternative chain identifier.
txHashStringYesTransaction hash from an OKX DEX API swap.
isFromMyProjectBooleanNoSet true to filter transactions under your API key. Default: false.

๐Ÿ‘‰ Optimize your DEX transactions with OKX's powerful API suite

Response Parameters

ParameterTypeDescription
chainIndexStringChain identifier.
chainIdString(Deprecated) Chain identifier.
txHashStringTransaction hash.
heightStringBlock height of the transaction.
txTimeStringUnix timestamp (ms) of transaction time.
statusStringpending/success/fail.
txTypeStringTransaction type: Approve, Wrap, Unwrap, or Swap.
fromAddressStringSender's wallet address.
dexRouterStringSmart contract interaction address.
toAddressStringRecipient's address.
fromTokenDetailsArrayDetails of the swapped token:
> symbolStringToken symbol.
> amountStringAmount in smallest units (e.g., wei).
> tokenAddressStringToken contract address.
toTokenDetailsArrayDetails of the received token:
> symbolStringToken symbol.
> amountStringReceived amount in smallest units.
> tokenAddressStringToken contract address.
referalAmountStringReferral bonus amount.
errorMsgStringError message (if failed).
gasLimitStringGas limit set for the transaction.
gasUsedStringActual gas consumed (in smallest units).
gasPriceStringGas price per unit.
txFeeStringTotal fee paid in chain's native currency.

Example Request

curl -X GET "https://web3.okx.com/api/v5/dex/aggregator/history?chainIndex=1&chainId=1&txHash=0x123...abc"

Example Response

{
  "chainIndex": "1",
  "chainId": "1",
  "txHash": "0x123...abc",
  "height": "15348921",
  "txTime": "1657823045000",
  "status": "success",
  "txType": "Swap",
  "fromAddress": "0x456...def",
  "dexRouter": "0x789...ghi",
  "toAddress": "0x012...jkl",
  "fromTokenDetails": [
    {
      "symbol": "ETH",
      "amount": "1000000000000000000",
      "tokenAddress": "0xEeeeeEeeeEeEee..."
    }
  ],
  "toTokenDetails": [
    {
      "symbol": "USDC",
      "amount": "1500000000",
      "tokenAddress": "0xa0b86991c6218b36..."
    }
  ],
  "gasUsed": "21000",
  "gasPrice": "50000000000",
  "txFee": "0.00105"
}

๐Ÿ‘‰ Explore advanced DEX trading strategies with OKX

FAQs

How long does it take to get transaction status?

Transaction status updates in near-real-time, typically within 2-3 block confirmations.

What if my transaction shows "pending" for too long?

This usually indicates network congestion. Check the blockchain explorer for gas fees or consider speeding up the transaction.

Can I track cross-chain swaps with this API?

No, this endpoint only supports single-chain transactions. For cross-chain swaps, use OKX's Bridge API.

Why is chainId marked as deprecated?

The ecosystem is transitioning to standardized chainIndex values. Update your integration accordingly.

How do I handle failed transactions?

Check the errorMsg field for details. Common issues include insufficient gas or slippage tolerance being exceeded.

Is historical data available through this API?

Yes, you can query transactions as far back as the blockchain's history allows.