eth_estimateGas - Mantle
Example code for the eth_estimateGas JSON-RPC method. Complete guide on how to use eth_estimateGas JSON-RPC in GetBlock Web3 documentation.
This method generates and returns an estimate of how much gas is necessary to allow a transaction to complete on the Mantle network. On Mantle v2, this includes both L1 and L2 gas costs.
Parameters
transaction
object
Transaction call object
blockParameter
string
(optional) Block number or "latest", "earliest", "pending"
Transaction Object:
from
string
(optional) Sender address
to
string
Recipient address
gas
string
(optional) Gas limit
gasPrice
string
(optional) Gas price in wei
value
string
(optional) Value to send
data
string
(optional) Transaction data
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": [{
"to": "0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245",
"value": "0xde0b6b3a7640000"
}],
"id": "getblock.io"
}'import axios from 'axios';
const data = JSON.stringify({
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"to": "0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245",
"value": "0xde0b6b3a7640000"
}],
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data)))
.catch(error => console.log(error));Response
Response Parameters:
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
string
Estimated gas amount in hexadecimal
Use Case
The eth_estimateGas method is essential for:
Transaction gas limit calculation
Transaction cost estimation
Smart contract deployment planning
DeFi transaction preparation
Wallet gas suggestions
Preventing out-of-gas errors
Error Handling
403
Forbidden
Missing or invalid ACCESS-TOKEN
-32000
Execution reverted
Transaction would fail
-32602
Invalid params
Invalid transaction object
Web3 Integration
Last updated
Was this helpful?