eth_estimateGas - Monad

This method generates an estimate of how much gas is needed for a transaction to complete. The transaction will not be added to the blockchain.

Parameters

ParameterTypeRequiredDescription
transactionobjectYesThe transaction call object.
transaction.fromstringNoThe address the transaction is sent from.
transaction.tostringNoThe address the transaction is directed to.
transaction.gasstringNoUpper limit of gas for the transaction (hex).
transaction.gasPricestringNoGas price in wei (hex).
transaction.valuestringNoValue sent with the transaction (hex).
transaction.datastringNoHash of the method signature and encoded parameters.
blockNumberstringNoBlock number in hex, or "latest", "earliest", "pending".

Request

curl

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": [{
        "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
        "to": "0x4bbeeb066ed09b7aed07bf39eee0460dfa261520",
        "value": "0xde0b6b3a7640000"
    }],
    "id": "getblock.io"
}'

estimateGas.js

javascriptimport axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_estimateGas",
    "params": [{
        "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
        "to": "0x4bbeeb066ed09b7aed07bf39eee0460dfa261520",
        "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": [{
        "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
        "to": "0x4bbeeb066ed09b7aed07bf39eee0460dfa261520",
        "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": [{
                "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
                "to": "0x4bbeeb066ed09b7aed07bf39eee0460dfa261520",
                "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
resultstringThe estimated gas required in hexadecimal (21000 = 0x5208 for simple transfers).

Use Case

The eth_estimateGas method is essential for:

  • Calculating transaction gas limits
  • Cost estimation before transactions
  • Smart contract interaction planning
  • Wallet gas limit suggestions
  • DeFi transaction preparation
  • Batch transaction planning

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN.
-32602Invalid paramsInvalid transaction parameters.
-32000Execution revertedTransaction would revert.
-32000Out of gasGas limit insufficient.
-32000Insufficient fundsNot enough MON for value + gas.

Web3 Integration

ethers-estimate.js

javascriptimport { ethers } from 'ethers';

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

const tx = {
    from: senderAddress,
    to: recipientAddress,
    value: ethers.parseEther('1.0'),
    data: '0x'
};

const gasEstimate = await provider.estimateGas(tx);
console.log('Estimated gas:', gasEstimate.toString());

// Add buffer for safety
const gasLimit = gasEstimate * 120n / 100n; // 20% buffer
javascriptimport { createPublicClient, http } from 'viem';
import { monad } from 'viem/chains';

// Create Viem client with GetBlock
const client = createPublicClient({
  chain: monad,
  transport: http("https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>"),
});

// Using the method through Viem
async function fetchAccountViem() {
    try {
        // Method-specific Viem implementation
        const result = await client.request({
            method: 'eth_estimateGas',
            param: [{
    from: senderAddress,
    to: recipientAddress,
    value: ethers.parseEther('1.0'),
    data: '0x'
}],
        });
        console.log('Result:', result);
        return result;
    } catch (error) {
        console.error('Viem Error:', error);
        throw error;
    }