Try it Live
Run FeeMarket examples in the interactive playground
BrandedFeeMarket
Tree-shakable namespace functions for fee market calculations.Overview
BrandedFeeMarket/ directory contains implementation functions organized as standalone modules. Each function operates on data passed as arguments (no instance methods).
All functions exported through FeeMarket.js namespace.
Pattern
Functions
EIP-1559 Base Fee
BaseFee.jsEIP-4844 Blob Fees
BlobBaseFee.jsfakeExponential helper for Taylor series approximation.
See eip4844.mdx#blobbasefee
fakeExponential.js
factor * e^(numerator / denominator)
Implementation:
Transaction Fees
calculateTxFee.jsState Operations
nextState.jsnextState with constant usage.
See calculations.mdx#projectbasefees
Query Functions
getBlobBaseFee.jsValidation
validateState.jsgasUsed >= 0gasLimit > 0gasUsed <= gasLimitbaseFee >= MIN_BASE_FEEexcessBlobGas >= 0blobGasUsed >= 0blobGasUsed <= MAX_BLOB_GAS_PER_BLOCK
- All values non-negative
maxPriorityFeePerGas <= maxFeePerGas1 <= blobCount <= 6(if blob tx)
Conversions
weiToGwei.jsFile Organization
Testing
FeeMarket.test.ts - Comprehensive test suite covering:- EIP-1559 base fee calculations (all scenarios)
- EIP-4844 blob fee calculations
- Transaction fee calculations
- State transitions
- Validation functions
- Edge cases and boundaries

