L0vdL0vd

eth_estimateGas

Estimates the gas a transaction would use, without sending it.

curl https://eth.l0vdinfra.com/YOUR_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0x000000000000000000000000000000000000dEaD","value":"0x1"}]}'

响应示例

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x5208"
}
参数与您的端点

参数

transactionobject必填
Transaction object.
blockstring可选
Block to estimate against. Defaults to "latest".

返回值

string Estimated gas, hex.

适用场景

Estimate how much gas a transaction would use before you sign and send it.

如何解读结果

Hex gas units: 0x5208 = 21,000, the cost of a plain native transfer.

提示

  • Add a safety margin (10 to 20 percent) when you set the gas limit; state can change between estimate and inclusion.
  • If the call would revert, you get an error with the revert data instead of a number.

相关方法