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.

Связанные методы