Skip to content

@tevm/common

The @tevm/common package provides chain-specific configuration and utilities for Tevm clients. It extends the functionality of ethereumjs/common and integrates with Viem's chain definitions.

Generated API Documentation: View the full API documentation in the evmts/tevm-monorepo/packages/common/docs folder.

Installation

npm install @tevm/common

Overview

The @tevm/common package provides:

  • Chain configuration management
  • Hardfork settings and EIP support
  • Consensus algorithm configuration
  • Network-specific settings
  • Extensive chain definitions

API Reference

Enumerations

Interfaces

Type Aliases

Functions

Supported Networks

The package includes configurations for numerous networks, including:

Layer 1 Networks

Layer 2 Networks

Alternative Networks

Development Networks

Usage Examples

Basic Configuration

import { createCommon } from '@tevm/common'
import { mainnet } from '@tevm/common'
 
const common = createCommon({
  ...mainnet,
  hardfork: 'shanghai'
})

Custom Chain Configuration

import { createCommon } from '@tevm/common'
 
const common = createCommon({
  name: 'Custom Chain',
  chainId: 1337,
  networkId: 1337,
  defaultHardfork: 'shanghai',
  consensus: {
    type: 'poa',
    algorithm: 'clique',
    clique: {
      period: 15,
      epoch: 30000
    }
  }
})

Using with Custom Crypto

import { createCommon, createMockKzg } from '@tevm/common'
 
const common = createCommon({
  ...mainnet,
  customCrypto: {
    kzg: createMockKzg()
  }
})

Network-Specific Configuration

import { createCommon, optimism, arbitrum } from '@tevm/common'
 
// Optimism configuration
const optimismCommon = createCommon({
  ...optimism,
  hardfork: 'bedrock'
})
 
// Arbitrum configuration
const arbitrumCommon = createCommon({
  ...arbitrum,
  hardfork: 'nitro'
})

Error Handling

The package throws specific errors for invalid configurations:

try {
  const common = createCommon({
    chainId: -1 // Invalid chain ID
  })
} catch (error) {
  if (error.code === 'INVALID_CHAIN_ID') {
    console.error('Invalid chain ID provided')
  }
}

See Also