Skip to main content

Try it Live

Run Hardfork examples in the interactive playground

    Operator-Style API

    lte mimics the ≤ operator for clearer code:
    import { LONDON, CANCUN } from 'tevm'
    
    // Operator-style (reads like <= operator)
    if (LONDON.lte(CANCUN)) {
      // ...
    }
    
    // Equivalent using isBefore + equals
    if (Hardfork.isBefore(LONDON, CANCUN) || Hardfork.equals(LONDON, CANCUN)) {
      // ...
    }
    

    Usage Patterns

    Maximum Version Checks

    import { Hardfork, CANCUN } from 'tevm'
    
    function validateMaxVersion(fork: BrandedHardfork) {
      if (!fork.lte(CANCUN)) {
        throw new Error(`Unsupported hardfork beyond Cancun: ${Hardfork.toString(fork)}`)
      }
    }
    

    Range Validation

    import { Hardfork, BERLIN, SHANGHAI } from 'tevm'
    
    function isInSupportedRange(fork: BrandedHardfork): boolean {
      return fork.gte(BERLIN) && fork.lte(SHANGHAI)
    }
    
    // Check if fork is between Berlin and Shanghai (inclusive)
    isInSupportedRange(LONDON)  // true
    

    Network Configuration

    import { Hardfork, PRAGUE } from 'tevm'
    
    function checkTestnetSupport(fork: BrandedHardfork) {
      if (fork.lte(PRAGUE)) {
        return "Fully supported"
      }
      return "Experimental - use with caution"
    }
    

    Chronological Ordering

    Uses chronological deployment order:
    BERLIN (10) < LONDON (11) < MERGE (14) < SHANGHAI (15) < CANCUN (16)
    

    Comparison with isBefore

    Unlike isBefore, lte returns true for equal versions:
    import { LONDON } from 'tevm'
    
    LONDON.lte(LONDON)       // true - equal counts
    LONDON.isBefore(LONDON)  // false - strictly less than
    

    Performance

    Time Complexity: O(1) - Array index comparison Typical Time: ~10-20ns per call

    See Also

    • gte - Greater than or equal
    • lt - Strictly less than (alias for isBefore)
    • isBefore - Strictly less than