Skip to main content
Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.

Gas Estimation and EIP-1559 Fees

This guide covers estimating gas for transactions and setting appropriate EIP-1559 fees using Voltaire’s provider and FeeMarket primitives.

EIP-1559 Fee Model

EIP-1559 replaced legacy gas price auctions with a predictable fee structure: The actual fee paid is: min(maxFeePerGas, baseFee + maxPriorityFeePerGas).

Getting Current Gas Prices

Fetch current network fee data using provider methods:

Estimating Gas for a Transaction

Use eth_estimateGas to simulate transaction execution and get the required gas:
Add a 20% buffer to gas estimates to account for state changes between estimation and execution: gasLimit = gasEstimate * 120n / 100n

Using GasEstimate Primitive

Voltaire provides a branded GasEstimate type for type-safe gas handling:

Calculating EIP-1559 Fees

Use the FeeMarket primitive to calculate effective fees:

Setting Appropriate Fees

Choose fee parameters based on urgency:

Predicting Future Base Fees

Use FeeMarket.BaseFee to calculate what the next block’s base fee will be:
The base fee adjusts by up to 12.5% per block based on utilization:
  • Block 100% full: base fee increases 12.5%
  • Block 50% full (target): base fee unchanged
  • Block 0% full: base fee decreases 12.5%

Using Fee History

Get historical fee data to understand network conditions:

Complete Transaction Cost Estimation

Combine gas estimation with fee calculation:

Blob Fees (EIP-4844)

For blob transactions, there’s a separate fee market:
eth_blobBaseFee is only available on networks with EIP-4844 (post-Cancun upgrade). It will error on older networks.

Contract Gas Estimation

For contract interactions, use the Contract module’s built-in estimation: