Get Gas Limit#
Retrieve estimated Gas Limit consumption through pre-execution of transaction information.
Request URL#
POST https://web3.okx.com/api/v6/dex/pre-transaction/gas-limit
Request Parameters#
| Parameter | Type | Required | Description | 
|---|---|---|---|
| chainIndex | String | Yes | Unique identifier for the chain. e.g., 1: Ethereum.See more here. | 
| fromAddress | String | Yes | From address. For transfer,Swap,Approve, it is a wallet address | 
| toAddress | String | Yes | To address. For transfer, it can be a token address or wallet address.For Swap,  it should be OKX DEX router address.For Approve, it is a token address | 
| txAmount | String | No | Transaction amount. Default value: 0.1. For Native token transactions ( where the fromTokenis 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 txAmountto0.The valle must use base unit of the native token, e.g., wei for ETH | 
| extJson | Object | No | Additional parameters for calldata and other information | 
extJson
| Parameter | Type | Required | Description | 
|---|---|---|---|
| inputData | String | No | Calldata | 
Response Parameters#
| Parameter | Type | Description | 
|---|---|---|
| gasLimit | String | Estimated gas limit | 
Request Example#
shell
curl --location --request POST 'https://web3.okx.com/api/v6/dex/pre-transaction/gas-limit' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z' \
--data-raw '{
    "fromAddress": "0x383c8208b4711256753b70729ba0cf0cda55efad",
    "toAddress": "0x4ad041bbc6fa102394773c6d8f6d634320773af4",
    "txAmount": "31600000000000000",
    "chainIndex": "1",
    "extJson": {
        "inputData":"041bbc6fa102394773c6d8f6d634320773af4"
    }
}'
Response Example#
200
{
    "code": "0",
    "data": [
        {
            "gasLimit": "652683"
        }
    ],
    "msg": ""
}
