Trade API

Simulate Transactions#

Simulate a blockchain transaction before executing it to see the expected outcomes and potential risks. Transaction simulate API is available to our enterprise customers only. If you are interested, please contact us dexapi@okx.com.

Request URL#

GET /api/v5/dex/pre-transaction/simulate

Request Parameters#

ParameterTypeRequiredDescription
fromAddressStringYesSource address.
toAddressStringYesDestination address.
chainIndexStringYesUnique identifier for the chain.
e.g., 1: Ethereum
See Supported Chains for more.
It supports EVM、SOL、SUI, more chains will be supported soon.
txAmountStringNoTransaction amount. Default value: 0.
1. For Native token transactions ( where the fromToken is native token. e.g., Ethereum), the txAmount can be set to the native token quantity, or retrieved from /swap api(e.g., txAmount = swapResponse.tx.value).
2.For non-native token transactions, set txAmount to 0.
The valle must use base unit of the native token, e.g., wei for ETH
extJsonObjectYesExtended information object containing the following fields:
> inputDataStringYesCall data for the transaction.
priorityFeeStringNoPriority fee. Only applicable to Solana.
gasPriceStringNoGas price for the transaction.

Response Parameters#

ParameterTypeDescription
intentionStringTransaction purpose. Valid values: "Swap", "Token Approval"
assetChangeArrayDetails of asset changes resulting from the transaction
> assetTypeStringAsset type. Valid values: "NATIVE", "ERC20", "SPLTOKEN","SUITOKEN"
> nameStringAsset name (e.g., "Ethereum")
> symbolStringAsset symbol (e.g., "ETH")
> decimalsNumberAsset decimal precision
> addressStringAsset contract address
> imageUrlStringURL to the asset's image
> rawValueStringAsset amount. Positive values indicate receiving assets, negative values indicate sending assets.
gasUsedStringGas consumed by the transaction
failReasonStringHuman-friendly explanation if the transaction would fail
risksArrayPotential risks identified in the transaction
> addressStringAddress associated with the risk
> addressTypeStringType of address. Valid values: "contract", "eoa"

Request Example#

shell
curl --location --request POST 'https://web3.okx.com/api/v5/dex/pre-transaction/simulate' \
--header 'OK-ACCESS-KEY: your-access-key' \
--header 'OK-ACCESS-SIGN: your-access-sign' \
--header 'OK-ACCESS-PASSPHRASE: your-passphrase' \
--header 'OK-ACCESS-TIMESTAMP: 2025-05-19T10:00:00.000Z' \
--header 'Content-Type: application/json' \
--data-raw '{
  "fromAddress": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
  "toAddress": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
  "chainIndex": "1",
  "txAmount": "0",
  "extJson": {
    "inputData": "0x38ed1739000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000000000042ab52c000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e0000000000000000000000000000000000000000000000000000000064794b4b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
  },
  "gasPrice": "12000000000"
}'

Response Example#

200
{
  "code": "0",
  "data": [
    {
      "intention": "SWAP",
      "assetChange": [
        {
          "assetType": "NATIVE",
          "name": "Ether",
          "symbol": "ETH",
          "decimals": 18,
          "address": "",
          "imageUrl": "",
          "rawValue": "-1000000000000000"
        },
        {
          "assetType": "ERC20",
          "name": "USD Coin",
          "symbol": "USDC",
          "decimals": 6,
          "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
          "imageUrl": "",
          "rawValue": "1000000000000000"
        }
      ],
      "gasUsed": "180000",
      "failReason": "",
      "risks": []
    }
  ],
  "msg": "success"
}