eth_estimateGas - Mantle

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

ParameterTypeDescription
transactionobjectTransaction call object
blockParameterstring(optional) Block number or "latest", "earliest", "pending"

Transaction Object:

FieldTypeDescription
fromstring(optional) Sender address
tostringRecipient address
gasstring(optional) Gas limit
gasPricestring(optional) Gas price in wei
valuestring(optional) Value to send
datastring(optional) Transaction data

Request

bashcurl --location --request POST 'https://shared.eu-central-1.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"
}'

estimateGas.js

javascriptimport 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://shared.eu-central-1.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));

estimate_gas.py

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = json.dumps({
    "jsonrpc": "2.0",
    "method": "eth_estimateGas",
    "params": [{
        "to": "0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245",
        "value": "0xde0b6b3a7640000"
    }],
    "id": "getblock.io"
})

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)
print(response.text)

main.rs

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "eth_estimateGas",
            "params": [{
                "to": "0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245",
                "value": "0xde0b6b3a7640000"
            }],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x5208"
}

Response Parameters:

FieldTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultstringEstimated 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

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN
-32000Execution revertedTransaction would fail
-32602Invalid paramsInvalid transaction object

Web3 Integration

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const gasEstimate = await provider.estimateGas({
    to: '0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245',
    value: ethers.parseEther('1.0')
});
console.log('Gas estimate:', gasEstimate.toString());
javascriptimport { createPublicClient, http, parseEther } from 'viem';
import { mantle } from 'viem/chains';

const client = createPublicClient({
    chain: mantle,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const gasEstimate = await client.estimateGas({
    to: '0xD85498dbEaEB1Df24BE52eED4F52eAc2Fbd56245',
    value: parseEther('1.0')
});
console.log('Gas estimate:', gasEstimate);