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

    UI Selector

    Build hardfork selector dropdown:
    import { Hardfork } from 'tevm'
    
    function buildHardforkSelector(): string {
      const names = Hardfork.allNames()
    
      const options = names
        .map(name => {
          const capitalized = name.charAt(0).toUpperCase() + name.slice(1)
          return `<option value="${name}">${capitalized}</option>`
        })
        .join('\n')
    
      return `<select name="hardfork">${options}</select>`
    }
    

    Configuration Validation

    Validate user input:
    import { Hardfork } from 'tevm'
    
    function validateHardfork(input: string): void {
      const validNames = Hardfork.allNames()
    
      if (!validNames.includes(input.toLowerCase())) {
        throw new Error(
          `Invalid hardfork: ${input}\n` +
          `Valid options: ${validNames.join(", ")}`
        )
      }
    }
    

    Timeline Generation

    Generate hardfork timeline:
    import { Hardfork } from 'tevm'
    
    function generateTimeline() {
      const names = Hardfork.allNames()
    
      return names.map((name, index) => ({
        index,
        name,
        displayName: name.charAt(0).toUpperCase() + name.slice(1)
      }))
    }
    
    // [
    //   { index: 0, name: "frontier", displayName: "Frontier" },
    //   { index: 1, name: "homestead", displayName: "Homestead" },
    //   ...
    // ]
    

    Feature Matrix

    Build feature availability table:
    import { Hardfork } from 'tevm'
    
    function generateFeatureMatrix() {
      const names = Hardfork.allNames()
    
      return names.map(name => {
        const fork = Hardfork(name)
        return {
          name,
          eip1559: fork.hasEIP1559(),
          push0: fork.hasEIP3855(),
          blobs: fork.hasEIP4844(),
          transientStorage: fork.hasEIP1153(),
          pos: fork.isPostMerge()
        }
      })
    }
    

    CLI Tools

    Display available hardforks:
    import { Hardfork } from 'tevm'
    
    function listHardforks() {
      const names = Hardfork.allNames()
    
      console.log("Available hardforks:")
      names.forEach((name, index) => {
        console.log(`  ${index.toString().padStart(2)}: ${name}`)
      })
    }
    

    Network Configuration

    Get supported versions:
    import { Hardfork } from 'tevm'
    
    function getSupportedVersions(minVersion: string, maxVersion: string) {
      const allNames = Hardfork.allNames()
      const minIndex = allNames.indexOf(minVersion)
      const maxIndex = allNames.indexOf(maxVersion)
    
      if (minIndex === -1 || maxIndex === -1) {
        throw new Error("Invalid version range")
      }
    
      return allNames.slice(minIndex, maxIndex + 1)
    }
    
    // Get all hardforks from London to Prague
    const supported = getSupportedVersions("london", "prague")
    

    Return Format

    Canonical Names:
    • Returns canonical names (not aliases)
    • “merge” not “paris”
    • “petersburg” not “constantinoplefix”
    Lowercase:
    • All names lowercase
    • Consistent formatting
    Complete List:
    • Includes all hardforks (historical and future)
    • 19 total hardforks as of Osaka

    Complete List

    [
      "frontier",         // 0 - Genesis
      "homestead",        // 1 - March 2016
      "dao",              // 2 - July 2016
      "tangerinewhistle", // 3 - October 2016
      "spuriousdragon",   // 4 - November 2016
      "byzantium",        // 5 - October 2017
      "constantinople",   // 6 - February 2019
      "petersburg",       // 7 - February 2019
      "istanbul",         // 8 - December 2019
      "muirglacier",      // 9 - January 2020
      "berlin",           // 10 - April 2021
      "london",           // 11 - August 2021
      "arrowglacier",     // 12 - December 2021
      "grayglacier",      // 13 - June 2022
      "merge",            // 14 - September 2022
      "shanghai",         // 15 - April 2023
      "cancun",           // 16 - March 2024
      "prague",           // 17 - Future
      "osaka"             // 18 - Future
    ]
    

    Performance

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

    See Also