eth_estimateGas

Estimates the Energy consumption required for a transaction.

Parameters

  1. Object - Transaction call object containing the following fields:

    Item NameData TypeDescription
    fromDATA, 20 BytesSender's address.
    toDATA, 20 BytesReceiver's address.
    gasQUANTITYFee limit. Retained for Ethereum compatibility; ignored by TRON.
    gasPriceQUANTITYEnergy price. Retained for Ethereum compatibility; ignored by TRON.
    valueQUANTITYAmount of TRX sent via call_value. (Unit: sun)
    dataDATAFunction selector and ABI-encoded parameters; lenient hex parsing is retained for legacy clients.
    inputDATAAlias for data; takes precedence when both are present. A non-empty value requires a 0x prefix and an even number of hex digits; an empty string represents empty bytes.

Return value

Returns the estimated Energy consumption as a hexadecimal QUANTITY. A regular TRX transfer uses TransferContract and does not execute a smart contract, so it returns 0x0. For a contract deployment or call:

  • When the node enables vm.estimateEnergy, the method returns energy_required from the Energy estimation API.
  • When vm.estimateEnergy is disabled, the node simulates a constant call and returns its energy_used value.

Example

Request

curl -X POST 'https://api.shasta.trongrid.io/jsonrpc' --data '{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "eth_estimateGas",
	"params": [{
		"from": "0xF0CC5A2A84CD0F68ED1667070934542D673ACBD8",
		"to": "0x70082243784DCDF3042034E7B044D6D342A91360",
		"gas": "0x01",
		"gasPrice": "0x8c",
		"value": "0x01",
		"data": "0x70a08231000000000000000000000000f0cc5a2a84cd0f68ed1667070934542d673acbd8"
	}]
}'

Response

{"jsonrpc":"2.0","id":1,"result":"0x0"}

In this example, 0x0 means that the request was handled as a regular TRX transfer and was estimated to use no Energy. Contract deployment and invocation estimates depend on the simulated execution.