Try it Live
Run Hardfork examples in the interactive playground
Hardfork Type
Hardforks are represented as branded strings:Core Operations
Version Comparison:API Methods
Constructors
fromString(value)- Parse hardfork name (case-insensitive, handles aliases)toString(fork)- Convert to normalized string name
Comparison Methods
compare(a, b)- Three-way comparison (-1, 0, 1)isAtLeast(current, target)- Check if current >= targetisBefore(current, target)- Check if current < targetisAfter(current, target)- Check if current > targetequals(a, b)- Equality checkgte(a, b)- Greater than or equal (alias)lte(a, b)- Less than or equal (alias)gt(a, b)- Greater than (alias)lt(a, b)- Less than (alias)
Feature Detection
hasEIP1559(fork)- EIP-1559 base fee mechanism (London+)hasEIP3855(fork)- PUSH0 opcode (Shanghai+)hasEIP4844(fork)- Blob transactions (Cancun+)hasEIP1153(fork)- Transient storage TLOAD/TSTORE (Cancun+)isPostMerge(fork)- Proof of Stake consensus (Merge+)
Collection Operations
allNames()- Get all hardfork names (chronological order)allIds()- Get all hardfork IDs (chronological order)range(start, end)- Get hardforks between two versions (inclusive)min(forks)- Find earliest hardfork in arraymax(forks)- Find latest hardfork in array
Constants
All hardfork constants available:Quick Examples
Version Gating
Network Configuration
Upgrade Path
Additional Documentation
- fundamentals.mdx - Introduction to Ethereum protocol upgrades
- hardforks.mdx - Complete hardfork timeline with all features
- usage-patterns.mdx - Common patterns and examples
- branded-hardfork.mdx - Branded type pattern
- wasm.mdx - WASM implementation status
Tree-Shaking
Import only what you need for optimal bundle size:Performance
All operations are O(1):- Comparisons: Simple array index lookups (~10-20ns)
- Feature detection: Single comparison + branch (~15-30ns)
- String parsing: Hash table lookup (~50-100ns)
- String conversion: Array index (~20-40ns)
Implementation
- Type: Branded string (
string & { __tag: "Hardfork" }) - Storage: Chronologically ordered array
- Comparison: Array index comparison
- Parsing: Hash table with lowercase keys
- Aliases: “paris” → MERGE, “constantinoplefix” → PETERSBURG
Best Practices
-
Use feature detection over version checks
-
Validate user input
-
Normalize for storage
-
Use convenience forms for readability
Related Primitives
- Network - Chain ID and network configuration
- Transaction - Transaction type selection based on hardfork
- Block - Block structure changes per hardfork

