交易 API

获取 Gas Limit#

通过交易信息的预执行,获取预估消耗的 Gaslimit 。

请求路径#

POST https://web3.okx.com/api/v5/dex/pre-transaction/gas-limit

请求参数#

ParameterTypeRequiredDescription
chainIndexString链唯一标识。(如1代表Ethereum。更多可查看这里。)
fromAddressStringFrom 地址。
toAddressStringTo 地址。
txAmountString交易金额。默认值:0
1.对于主链币交易(当fromToken为主链币时,例如 ETH ),txAmount可设置为主链币的数量,或通过 /swap API获取(例如:txAmount = swapResponse.tx.value)。
2.对于代币交易,需将 txAmount 设为0。
金额必须使用主链币的基础单位(如ETH对应wei)。
extJsonObject扩展参数,用于添加 calldata 等信息

extJson

ParameterTypeRequiredDescription
inputDataStringcalldata

响应参数#

ParameterTypeDescription
gasLimitString预估gas limit数额

请求示例#

shell
curl --location --request POST 'https://web3.okx.com/api/v5/dex/pre-transaction/gas-limit' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-PROJECT: 86af********d1bc' \
--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 '{
    "fromAddr": "0x383c8208b4711256753b70729ba0cf0cda55efad",
    "toAddr": "0x4ad041bbc6fa102394773c6d8f6d634320773af4",
    "txAmount": "31600000000000000",
    "chainIndex": "1",
    "extJson": {
        "inputData":"041bbc6fa102394773c6d8f6d634320773af4"
    }
}'

响应示例#

200
{
        "code": "0",
        "data": [
            {
              "gasLimit": "652683"
            }
        ],
        "msg": ""
}