Use this file to discover all available pages before exploring further.
Try it Live
Run Chain examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Chain API.
Ethereum chain IDs are unique numeric identifiers for blockchain networks that prevent replay attacks and enable multi-chain transaction signing. This guide covers chain ID fundamentals using Tevm.
A chain ID is a numeric identifier that uniquely identifies an Ethereum network. Every blockchain network (mainnet, testnet, L2, sidechain) has its own chain ID.Common Chain IDs:
Chain IDs solve the replay attack problem introduced by EIP-155. Before EIP-155, a transaction signed on one network could be replayed on another network with identical account state.
// Without chain ID: Transaction could be replayed on any networkconst tx = { to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb2", value: "1000000000000000000", // 1 ETH nonce: 5, gasPrice: "20000000000", gasLimit: "21000"};// Signed on mainnet, but could be replayed on:// - Goerli (same addresses exist)// - Private network (if you have funds there)// - ANY network with identical account state
EIP-155 requires chain ID in transaction signatures, preventing cross-chain replay:
import { Transaction } from 'tevm';// Chain ID embedded in signatureconst mainnetTx = Transaction.fromLegacy({ to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb2", value: "1000000000000000000", nonce: 5, gasPrice: "20000000000", gasLimit: "21000", chainId: 1 // Mainnet only - cannot be replayed on other networks});const sepoliaTx = Transaction.fromLegacy({ to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb2", value: "1000000000000000000", nonce: 5, gasPrice: "20000000000", gasLimit: "21000", chainId: 11155111 // Sepolia only - different signature than mainnet});// Same transaction parameters, different signatures due to chain ID
Chain IDs are signed into transactions, making them network-specific:
import { Transaction } from 'tevm';import { secp256k1 } from 'tevm/crypto';const privateKey = Bytes32(); // Your private key// Create transaction for specific networkconst tx = Transaction.fromEIP1559({ to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb2", value: "1000000000000000000", nonce: 0, chainId: 1, // Mainnet maxFeePerGas: "30000000000", maxPriorityFeePerGas: "2000000000", gasLimit: "21000"});// Sign with chain ID included in signatureconst signed = tx.sign(privateKey);// Extract chain ID from signed transactionconsole.log(signed.chainId); // 1 (mainnet)// This transaction can ONLY be broadcast to mainnet// Attempting to broadcast to Sepolia will fail
Network identification (chain metadata) and replay protection (chain ID in signature) serve different purposes:
import { Chain, Transaction } from 'tevm';// Network identification: Get chain metadataconst chain = Chain.fromId(1);console.log(chain?.name); // "Ethereum Mainnet"console.log(chain?.nativeCurrency.symbol); // "ETH"console.log(chain?.rpc[0]); // RPC endpointconsole.log(chain?.explorers?.[0].url); // "https://etherscan.io"// Replay protection: Chain ID in transaction signatureconst tx = Transaction.fromEIP1559({ to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb2", chainId: 1, // Signed into transaction - prevents replay // ... other fields});// Chain metadata helps you:// - Display network name to users// - Connect to correct RPC endpoint// - Link to block explorers// - Show correct currency symbols// Chain ID in signature ensures:// - Transaction only valid on intended network// - Cannot be replayed on other chains// - Network-specific transaction validity