Skip to main content

Try it Live

Run Hardfork examples in the interactive playground

    Chronological Order

    Returns hardforks in deployment order:
    [
      FRONTIER, HOMESTEAD, DAO, TANGERINE_WHISTLE, SPURIOUS_DRAGON,
      BYZANTIUM, CONSTANTINOPLE, PETERSBURG, ISTANBUL, MUIR_GLACIER,
      BERLIN, LONDON, ARROW_GLACIER, GRAY_GLACIER, MERGE,
      SHANGHAI, CANCUN, PRAGUE, OSAKA
    ]
    

    Usage Patterns

    Feature Matrix Generation

    Generate complete feature matrix:
    import { Hardfork } from 'tevm'
    
    function generateFeatureMatrix() {
      const forks = Hardfork.allIds()
    
      return forks.map(fork => ({
        name: Hardfork.toString(fork),
        consensus: fork.isPostMerge() ? "PoS" : "PoW",
        eip1559: fork.hasEIP1559(),
        push0: fork.hasEIP3855(),
        blobs: fork.hasEIP4844(),
        transientStorage: fork.hasEIP1153()
      }))
    }
    
    // [
    //   { name: "frontier", consensus: "PoW", eip1559: false, ... },
    //   { name: "homestead", consensus: "PoW", eip1559: false, ... },
    //   ...
    //   { name: "cancun", consensus: "PoS", eip1559: true, ... },
    // ]
    

    Iterate All Hardforks

    Process each hardfork:
    import { Hardfork } from 'tevm'
    
    function analyzeAllHardforks() {
      const forks = Hardfork.allIds()
    
      for (const fork of forks) {
        console.log(`\n${Hardfork.toString(fork).toUpperCase()}`)
        console.log(`  EIP-1559: ${fork.hasEIP1559()}`)
        console.log(`  PUSH0: ${fork.hasEIP3855()}`)
        console.log(`  Blobs: ${fork.hasEIP4844()}`)
        console.log(`  Transient: ${fork.hasEIP1153()}`)
        console.log(`  PoS: ${fork.isPostMerge()}`)
      }
    }
    

    Find Feature Introduction

    Find when feature was introduced:
    import { Hardfork } from 'tevm'
    
    function findFeatureIntroduction(
      featureCheck: (fork: BrandedHardfork) => boolean
    ): BrandedHardfork | null {
      const forks = Hardfork.allIds()
    
      for (const fork of forks) {
        if (featureCheck(fork)) {
          return fork
        }
      }
    
      return null
    }
    
    // Find when EIP-1559 was introduced
    const eip1559Fork = findFeatureIntroduction(fork => fork.hasEIP1559())
    console.log(Hardfork.toString(eip1559Fork))  // "london"
    
    // Find when blobs were introduced
    const blobsFork = findFeatureIntroduction(fork => fork.hasEIP4844())
    console.log(Hardfork.toString(blobsFork))  // "cancun"
    

    Network Configuration

    Get supported hardfork range:
    import { Hardfork, BERLIN, PRAGUE } from 'tevm'
    
    function getSupportedRange(min: BrandedHardfork, max: BrandedHardfork) {
      const allForks = Hardfork.allIds()
    
      return allForks.filter(fork =>
        fork.isAtLeast(min) && fork.lte(max)
      )
    }
    
    // Get all hardforks from Berlin to Prague
    const supported = getSupportedRange(BERLIN, PRAGUE)
    // [BERLIN, LONDON, ARROW_GLACIER, GRAY_GLACIER, MERGE, SHANGHAI, CANCUN, PRAGUE]
    

    Sorting

    Sort hardforks chronologically:
    import { Hardfork, CANCUN, BERLIN, SHANGHAI } from 'tevm'
    
    const unsorted = [CANCUN, BERLIN, SHANGHAI]
    
    // Sort using compare
    const sorted = unsorted.sort(Hardfork.compare)
    // [BERLIN, SHANGHAI, CANCUN]
    
    // Verify against canonical order
    const allForks = Hardfork.allIds()
    const expectedOrder = allForks.filter(f => unsorted.includes(f))
    console.log(sorted === expectedOrder)  // true (same order)
    

    Comparison with allNames

    allIds():
    • Returns BrandedHardfork[] constants
    • Type-safe, can call methods directly
    • Better for programmatic use
    allNames():
    • Returns string[] names
    • Better for display/UI
    • Requires parsing back to hardfork
    import { Hardfork } from 'tevm'
    
    // allIds - type-safe, direct method calls
    const ids = Hardfork.allIds()
    ids.forEach(fork => {
      console.log(fork.hasEIP1559())  // ✅ Direct method call
    })
    
    // allNames - requires parsing
    const names = Hardfork.allNames()
    names.forEach(name => {
      const fork = Hardfork(name)
      console.log(fork.hasEIP1559())  // ⚠️ Must parse first
    })
    

    Performance

    Time Complexity: O(n) where n = number of hardforks (19) Typical Time: ~100-200ns (returns pre-allocated array)

    See Also

    • allNames - Get hardfork names as strings
    • range - Get hardforks between two versions
    • compare - Sort hardforks chronologically