eth_estimateGas - Polygon
Example code for the eth_estimateGas json-rpc method. Сomplete guide on how to use eth_estimateGas json-rpc in GetBlock.io Web3 documentation.
Parameters
Parameter
Type
Required
Description
Transaction Object
Field
Type
Required
Description
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"from": "0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1",
"to": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
"value": "0x0",
"data": "0xa9059cbb000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA960450000000000000000000000000000000000000000000000056bc75e2d63100000"
}],
"id": "getblock.io"
}'import axios from 'axios';
const url = 'https://go.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
method: 'eth_estimateGas',
params: [{
from: '0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1',
to: '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
value: '0x0',
data: '0xa9059cbb000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA960450000000000000000000000000000000000000000000000056bc75e2d63100000'
}],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
const gasEstimate = parseInt(response.data.result, 16);
console.log('Estimated Gas:', gasEstimate);
})
.catch(error => console.error(error));Response
Response Parameters
Field
Type
Description
Use Case
Example: Calculate Transaction Cost
Error Handling
Status Code
Error Message
Cause
Web3 Integration
Last updated
Was this helpful?