Skip to main content

Overview

FeeMarket implements Ethereum’s dynamic fee mechanisms: EIP-1559 for base fees and EIP-4844 for blob fees. Use it to calculate next block fees, validate transactions, project fee trends, and estimate costs.

Types

State

Complete fee market state for a block:

TxFeeParams

Transaction fee parameters for EIP-1559:

BlobTxFeeParams

Extended parameters for blob transactions (EIP-4844):

TxFee

Calculated transaction fee breakdown:

BlobTxFee

Extended fee breakdown for blob transactions:

EIP-1559 Methods

BaseFee

Calculate next block’s base fee using the EIP-1559 formula.
Formula:
  • gasTarget = gasLimit / 2
  • If gasUsed > gasTarget: base fee increases (up to 12.5%)
  • If gasUsed < gasTarget: base fee decreases (up to 12.5%)
  • If gasUsed == gasTarget: base fee unchanged
  • Minimum base fee: 7 wei

calculateTxFee

Calculate effective transaction fee breakdown.
Formula:
  • effectiveGasPrice = min(maxFeePerGas, baseFee + maxPriorityFeePerGas)
  • priorityFee = effectiveGasPrice - baseFee

canIncludeTx

Check if transaction meets minimum fee requirements.
For blob transactions, also checks maxFeePerBlobGas >= blobBaseFee.

validateTxFeeParams

Validate transaction fee parameters.
Validates:
  • maxFeePerGas >= 0
  • maxPriorityFeePerGas >= 0
  • maxPriorityFeePerGas <= maxFeePerGas
  • baseFee >= 0
  • For blob txs: blobCount between 1 and 6

EIP-4844 Methods

BlobBaseFee

Calculate blob base fee using EIP-4844 exponential formula.
Formula: Uses Taylor series approximation of MIN_BLOB_BASE_FEE * e^(excessBlobGas / UPDATE_FRACTION)

calculateExcessBlobGas

Calculate excess blob gas for next block.
Formula: max(0, parentExcess + parentBlobGasUsed - TARGET_BLOB_GAS_PER_BLOCK)

calculateBlobTxFee

Calculate complete blob transaction fee breakdown.

State Methods

nextState

Calculate next block’s complete fee market state.

validateState

Validate block state parameters.
Validates:
  • gasUsed >= 0 and <= gasLimit
  • gasLimit > 0
  • baseFee >= MIN_BASE_FEE (7 wei)
  • excessBlobGas >= 0
  • blobGasUsed >= 0 and <= MAX_BLOB_GAS_PER_BLOCK

projectBaseFees

Project base fees over multiple blocks.
Useful for fee trend analysis and gas price estimation.

Utility Functions

gweiToWei

Convert gwei to wei.

weiToGwei

Convert wei to gwei for display.

Constants

EIP-1559 Constants

EIP-4844 Constants

Usage Examples

Estimate Transaction Cost

Validate Before Submission

  • Gas - Gas limits and usage
  • Transaction - Transaction types
  • KZG - Blob commitment cryptography
  • EIP-1559 - Fee market specification
  • EIP-4844 - Blob transaction specification