Skip to main content

GasEstimate

GasEstimate represents the estimated gas required for a transaction, typically returned by eth_estimateGas RPC method. Always add buffer (20-30%) before using as gasLimit.

Type Definition

Branded bigint representing estimated gas (always non-negative).

Gas Estimation Flow

API

Constructors

from(value)

Create GasEstimate from number, bigint, or string.
Throws: InvalidFormatError if value is negative.

Conversions

toNumber(estimate)

Convert to number.

toBigInt(estimate)

Convert to bigint (identity operation).

toHex(estimate)

Convert to hex string.

Comparisons

equals(est1, est2)

Check equality.

compare(est1, est2)

Compare values (-1, 0, 1).

Utilities

withBuffer(estimate, percentage)

Add percentage buffer to estimate.
Recommended buffers:
  • Standard: 20-25%
  • Conservative: 30-40%
  • Network congestion: 50%+

toGasLimit(estimate)

Convert to gas limit (typically after adding buffer).

Usage Examples

Basic Estimation

Add Buffer and Send Transaction

Compare Estimation Strategies

Handle Network Congestion

Why Add Buffer?

eth_estimateGas returns the minimum gas needed under ideal conditions:
  1. State changes: Between estimation and execution, blockchain state may change
  2. Gas costs: Hard forks can change opcode gas costs
  3. Execution paths: Conditional logic may take different paths
  4. Rounding: EVM operations round up, estimation may round down
Without buffer: Transaction may fail with “out of gas” error. With buffer: Transaction succeeds, excess gas refunded.

Estimation Strategies

Standard (20-25%)

Good for:
  • Simple transfers
  • Known contract calls
  • Stable network conditions

Conservative (30-40%)

Good for:
  • Complex contract interactions
  • First-time contract calls
  • Unknown execution paths

Very Safe (50%+)

Good for:
  • Network congestion
  • Critical transactions
  • Maximum safety needed

Common Estimates

EIPs

  • EIP-150: Gas cost changes (1/64th rule)
  • EIP-2929: Cold/warm storage access costs
  • EIP-3529: Refund reduction (doesn’t affect estimation)

See Also