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#
Parameter | Type | Required | Description |
---|---|---|---|
fromAddress | String | Yes | Source address. |
toAddress | String | Yes | Destination address. |
chainIndex | String | Yes | Unique identifier for the chain. e.g., 1 : EthereumSee Supported Chains for more. It supports EVM、SOL、SUI, more chains will be supported soon. |
txAmount | String | No | Transaction 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 |
extJson | Object | Yes | Extended information object containing the following fields: |
> inputData | String | Yes | Call data for the transaction. |
priorityFee | String | No | Priority fee. Only applicable to Solana. |
gasPrice | String | No | Gas price for the transaction. |
Response Parameters#
Parameter | Type | Description |
---|---|---|
intention | String | Transaction purpose. Valid values: "Swap", "Token Approval" |
assetChange | Array | Details of asset changes resulting from the transaction |
> assetType | String | Asset type. Valid values: "NATIVE", "ERC20", "SPLTOKEN","SUITOKEN" |
> name | String | Asset name (e.g., "Ethereum") |
> symbol | String | Asset symbol (e.g., "ETH") |
> decimals | Number | Asset decimal precision |
> address | String | Asset contract address |
> imageUrl | String | URL to the asset's image |
> rawValue | String | Asset amount. Positive values indicate receiving assets, negative values indicate sending assets. |
gasUsed | String | Gas consumed by the transaction |
failReason | String | Human-friendly explanation if the transaction would fail |
risks | Array | Potential risks identified in the transaction |
> address | String | Address associated with the risk |
> addressType | String | Type 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"
}