> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# FeeMarket

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/fee-market.ts">
  Run FeeMarket examples in the interactive playground
</Card>

# FeeMarket

Type-safe Ethereum fee market calculations for EIP-1559 and EIP-4844.

<Tip>
  **New to Ethereum fee markets?** Start with [Fundamentals](/primitives/feemarket/fundamentals) to learn about base fees, priority fees, and blob gas pricing.
</Tip>

## 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

```typescript theme={null}
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](./types) - Complete block fee market state and next state calculations

### EIP-1559 (Base Fees)

* [EIP-1559 Calculations](./eip1559) - Calculate base fees, gas targets, and utilization checks

### EIP-4844 (Blob Fees)

* [EIP-4844 Calculations](./eip4844) - Calculate blob base fees and excess blob gas

### Transaction Fees

* [Transaction Fee Calculations](./calculations) - Calculate EIP-1559 and blob transaction fees

### Projections

* [Fee Projections](./calculations) - Project future base fees across multiple blocks

### Validation

* [Validation Utilities](./utilities) - Validate transaction fee parameters and block state

## Constants

### EIP-1559

```typescript theme={null}
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](./constants.mdx#eip1559)

### EIP-4844

```typescript theme={null}
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](./constants.mdx#eip4844)

## Types

### Core Types

* [State](./types.mdx#state) - Block fee market state
* [Eip1559State](./types.mdx#eip1559state) - EIP-1559 state subset
* [Eip4844State](./types.mdx#eip4844state) - EIP-4844 state subset

### Transaction Types

* [TxFeeParams](./types.mdx#txfeeparams) - Transaction fee parameters
* [BlobTxFeeParams](./types.mdx#blobtxfeeparams) - Blob transaction fee parameters
* [TxFee](./types.mdx#txfee) - Transaction fee result
* [BlobTxFee](./types.mdx#blobtxfee) - Blob transaction fee result

## Learning Resources

* [Fundamentals](./fundamentals.mdx) - Fee market mechanics, base fee adjustment, priority fees, blob gas
* [usage-patterns.mdx](./usage-patterns.mdx) - Common patterns for fee estimation and transaction cost calculation

## BrandedFeeMarket

See [branded-feemarket.mdx](./branded-feemarket.mdx) for tree-shakable namespace functions.

## WASM Support

Pure TypeScript implementation is optimal for FeeMarket. See [wasm.mdx](./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

* [EIP-1559: Fee market change for ETH 1.0 chain](https://eips.ethereum.org/EIPS/eip-1559)
* [EIP-4844: Shard Blob Transactions](https://eips.ethereum.org/EIPS/eip-4844)
* [Fee Estimation Guide](./usage-patterns.mdx) - Real-world patterns

## Related

* [FeeMarket (Effect)](https://voltaire-effect.tevm.sh/primitives/fee-market) - Effect.ts integration with Schema validation
* [Address](/primitives/address) - Ethereum addresses
* [Transaction](/primitives/transaction) - Transaction types
* [Uint](/primitives/uint) - 256-bit unsigned integers
* [Hex](/primitives/hex) - Hex string utilities
