Skip to main content

Try it Live

Run FeeMarket examples in the interactive playground

FeeMarket

Type-safe Ethereum fee market calculations for EIP-1559 and EIP-4844.
New to Ethereum fee markets? Start with Fundamentals to learn about base fees, priority fees, and blob gas pricing.

Overview

FeeMarket provides complete fee calculation and projection for Ethereum’s two fee markets:
  • EIP-1559: Dynamic base fee adjusting based on block utilization (gas)
  • EIP-4844: Exponential blob fee pricing for data availability (blobs)

Quick Start

import * as FeeMarket from 'tevm';

// Construct next base fee
const nextBaseFee = FeeMarket.BaseFee(
  15_000_000n,     // gas used
  30_000_000n,     // gas limit
  1_000_000_000n   // current base fee (1 gwei)
);

// Construct priority fee
const priorityFee = FeeMarket.PriorityFee({
  maxFeePerGas: 2_000_000_000n,
  maxPriorityFeePerGas: 1_000_000_000n,
  baseFee: 1_000_000_000n
});

// Construct blob base fee
const blobBaseFee = FeeMarket.BlobBaseFee(262_144n);

API Methods

State Management

  • State Types - Complete block fee market state and next state calculations

EIP-1559 (Base Fees)

EIP-4844 (Blob Fees)

Transaction Fees

Projections

Validation

Constants

EIP-1559

FeeMarket.Eip1559.MIN_BASE_FEE                  // 7n wei
FeeMarket.Eip1559.BASE_FEE_CHANGE_DENOMINATOR   // 8n (12.5%)
FeeMarket.Eip1559.ELASTICITY_MULTIPLIER         // 2n (target = limit/2)
See constants.mdx#eip1559

EIP-4844

FeeMarket.Eip4844.MIN_BLOB_BASE_FEE              // 1n wei
FeeMarket.Eip4844.BLOB_BASE_FEE_UPDATE_FRACTION  // 3338477n
FeeMarket.Eip4844.TARGET_BLOB_GAS_PER_BLOCK      // 393216n (3 blobs)
FeeMarket.Eip4844.BLOB_GAS_PER_BLOB              // 131072n
FeeMarket.Eip4844.MAX_BLOBS_PER_BLOCK            // 6n
See constants.mdx#eip4844

Types

Core Types

Transaction Types

Learning Resources

  • Fundamentals - Fee market mechanics, base fee adjustment, priority fees, blob gas
  • usage-patterns.mdx - Common patterns for fee estimation and transaction cost calculation

BrandedFeeMarket

See branded-feemarket.mdx for tree-shakable namespace functions.

WASM Support

Pure TypeScript implementation is optimal for FeeMarket. See wasm.mdx for details.

Performance

  • BaseFee: ~4M ops/sec
  • BlobBaseFee: ~100K ops/sec
  • calculateTxFee: ~20M ops/sec
  • nextState: ~2M ops/sec
  • projectBaseFees: ~1M ops/sec per block
See FeeMarket.bench.ts for detailed benchmarks.

References