eth_estimateGas

eth_estimateGas(callObject, blockTag?) → quantity

Returns an estimate of how much gas a transaction will need if it were executed at the given block. The node simulates the call (no state change, no transaction) and reports the gas used. Use this before signing to set a sane gas field; pad the result by 20–30% for production transactions because actual on-chain gas can drift slightly with state changes between simulation and inclusion.

Parameters

Name Type Required Description
callObject object Transaction call object. Common fields: from (sender address), to (target address — omit for contract creation), value (hex aokrw to forward), data (hex calldata), gasPrice / maxFeePerGas / maxPriorityFeePerGas (optional, used for base-fee-aware simulation).
blockTag string - Block to simulate against — latest (default), earliest, pending, safe, finalized, or a hex block number. On Maroo's CometBFT consensus, safe and finalized resolve to the latest committed block (instant finality).

Returns

Type: string

Estimated gas amount, hex-encoded with 0x prefix (e.g. 0x5208 = 21,000 for a plain transfer).

Errors

Code Name Description
-32000 execution reverted The simulated call reverted (target contract threw, PCL policy denied, etc.). The error data carries the original revert reason — decode it to know whether the gas estimate is missing because the call would actually fail.
-32000 gas required exceeds allowance The estimated gas exceeds the block gas limit, meaning the transaction cannot be included. Usually the call is in an infinite loop or hits an unbounded data structure.
-32602 Invalid params The callObject is malformed — missing from, malformed addresses, or invalid hex in value/data.

Examples

ethers.js v6 — estimate before sending

ethers.js calls eth_estimateGas under the hood. For contract calls, pass data from iface.encodeFunctionData(...).

import { JsonRpcProvider, parseEther } from "ethers";

const provider = new JsonRpcProvider("https://rpc-testnet.maroo.io");

const gas = await provider.estimateGas({
  from:  "0xSenderAddress",
  to:    "0xRecipientAddress",
  value: parseEther("1500000"),  // 1,500,000 OKRW
});
console.log("Estimated gas:", gas.toString());

// Pad by ~25% for headroom in production.
const safeGas = (gas * 125n) / 100n;

Raw cURL

0x13DA329B6336471800000 decodes to 1.5 × 10^24 aokrw = 1,500,000 OKRW. Returns { jsonrpc, id, result: "0x5208" } (21,000 gas) for a plain transfer.

curl -X POST https://rpc-testnet.maroo.io \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_estimateGas",
    "params": [{
      "from":  "0xSenderAddress",
      "to":    "0xRecipientAddress",
      "value": "0x13DA329B6336471800000"
    }, "latest"],
    "id": 1
  }'
Source: maroo
ESC
Type to search