eth_estimateGas
Generates and returns an estimate of gas required to execute a transaction.
Parameters
- Transaction Object - Same as eth_call
from
(optional): Sender addressto
: Recipient or contract addressgas
(optional): Gas limitgasPrice
(optional): Gas pricevalue
(optional): Value in weidata
: Encoded function data
{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"value": "0x9184e72a"
}],
"id": 1
}
Returns
QUANTITY
- The estimated gas amount.
Implementation Examples
- cURL
- JavaScript
curl -X POST https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"data": "0x"
}],
"id": 1
}'
// Using ethers.js
const tx = {
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
value: ethers.parseUnits("1", 6), // 1 TRX
data: "0x"
};
const gasEstimate = await provider.estimateGas(tx);
console.log('Estimated gas:', gasEstimate.toString());
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5208"
}