proxy/eth_estimateGas - 估算gas用量
使用proxy模块的eth_estimateGas方法估算交易的gas用量。
API调用
GET|POST /api
查询|表单参数:
- module:proxy
- action:eth_estimateGas
- to:目标账号
- value:交易金额
- gasPrice:gas价格
- gas:gas上限
- apikey:etherscan API密钥
API返回结果
返回结果为一个JSON对象,主要字段如下:
- jsonrpc:RPC版本号,2.0
- id:RPC请求编号
- result:调用结果,估算的gas消耗量
- error:错误信息
示例代码
以curl为例的调用代码如下,也可以点击这里查看浏览器中的运行结果:
~$ curl https://api.etherscan.io/api?module=proxy&action=eth_estimateGas&to=0xf0160428a8552ac9bb7e050d90eeade4ddd52843&value=0xff22&gasPrice=0x051da038cc&gas=0xffffff&apikey=YourApiKeyToken
返回结果如下:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "invalid argument 0: json: cannot unmarshal hex number with leading zero digits into Go value of type *hexutil.Big"
}
}