klay_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.

The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including Klaytn Virtual Machine mechanics and node performance.

📘

Supported on Klaytn (mainnet) only.

Parameters

Request

NameTypeDescription
callObjectObjectThe transaction call object. See the next table for the object's properties.

callObject has the following properties:

NameTypeDescription
from20-byte DATA(optional) The address the transaction is sent from.
to20-byte DATA(optional when testing the deployment of a new contract) The address the transaction is directed to.
gasQUANTITY(optional) Integer of the upper gas limit provided for the gas estimation. If no gas limit is specified, the Klaytn node uses the designated gas limit as an upper bound.
gasPriceQUANTITY(optional) Integer of the gasPrice used for each paid gas.
valueQUANTITY(optional) Integer of the value sent with this transaction.
inputDATA(optional) Hash of the method signature and encoded parameters. It replaces data field, but 'data` field is still supported for backward compatibility.

Result

TypeDescription
QUANTITYThe amount of gas used.

API Endpoint

The format of a Klaytn API endpoint is
https://open-platform.nodereal.io/{{apiKey}}/klaytn/

Here is an example:
https://open-platform.nodereal.io/4c0a1c23661a4e26bcbcwed461e34ea9/klaytn/

Example

// Request
curl https://open-platform.nodereal.io/{{apiKey}}/klaytn/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc": "2.0", "method": "klay_estimateGas", "params": [{"from": "0x3f71029af4e252b25b9ab999f77182f0cd3bc085", "to": "0x87ac99835e67168d4f9a40580f8f5c33550ba88b", "gas": "0x100000", "gasPrice": "0x5d21dba00", "value": "0x0", "input": "0x8ada066e"}], "id": 1}'

// Result
{
  "jsonrpc": "2.0","id":1,
  "result": "0x5208" // 21000
}