Chains
Chain definitions and lookup utilities for common EVM-compatible blockchains.
import { chains, getChain } from '@web3marketlabs/sdk'ChainConfig Interface
Every chain is represented by the ChainConfig interface:
interface ChainConfig {
/** Numeric chain ID */
id: number
/** Human-readable chain name */
name: string
/** The chain's native currency */
nativeCurrency: {
name: string
symbol: string
decimals: number
}
/** RPC endpoint URLs */
rpcUrls: {
public: { http: readonly string[] }
default: { http: readonly string[] }
}
/** Block explorer URLs (if available) */
blockExplorers?: {
etherscan?: { name: string; url: string }
default: { name: string; url: string }
}
/** Whether this is a testnet */
testnet?: boolean
}chains
A Record<string, ChainConfig> containing all supported chain configurations, keyed by their string identifier.
import { chains } from '@web3marketlabs/sdk'
chains.ethereum // { id: 1, name: 'Ethereum', ... }
chains.sepolia // { id: 11155111, name: 'Sepolia', ... }
chains.base // { id: 8453, name: 'Base', ... }Available Chains
| Key | ID | Name | Native Currency | Symbol | Testnet |
|---|---|---|---|---|---|
anvil | 31337 | Anvil | Ether | ETH | Yes |
ethereum | 1 | Ethereum | Ether | ETH | No |
sepolia | 11155111 | Sepolia | Sepolia Ether | ETH | Yes |
arbitrum | 42161 | Arbitrum One | Ether | ETH | No |
arbitrumSepolia | 421614 | Arbitrum Sepolia | Ether | ETH | Yes |
base | 8453 | Base | Ether | ETH | No |
baseSepolia | 84532 | Base Sepolia | Ether | ETH | Yes |
polygon | 137 | Polygon | POL | POL | No |
polygonAmoy | 80002 | Polygon Amoy | POL | POL | Yes |
optimism | 10 | Optimism | Ether | ETH | No |
optimismSepolia | 11155420 | Optimism Sepolia | Ether | ETH | Yes |
All chains have decimals: 18 for their native currency. The Anvil chain uses http://127.0.0.1:8545 as its RPC endpoint and does not have block explorers configured.
Default RPC Endpoints
| Chain | Default RPC URL |
|---|---|
| Anvil | http://127.0.0.1:8545 |
| Ethereum | https://eth.llamarpc.com |
| Sepolia | https://rpc.sepolia.org |
| Arbitrum One | https://arb1.arbitrum.io/rpc |
| Arbitrum Sepolia | https://sepolia-rollup.arbitrum.io/rpc |
| Base | https://mainnet.base.org |
| Base Sepolia | https://sepolia.base.org |
| Polygon | https://polygon-rpc.com |
| Polygon Amoy | https://rpc-amoy.polygon.technology |
| Optimism | https://mainnet.optimism.io |
| Optimism Sepolia | https://sepolia.optimism.io |
getChain(chainIdOrName)
Look up a chain by its numeric chain ID or string key name.
function getChain(chainIdOrName: number | string): ChainConfig | undefinedParameters
| Parameter | Type | Description |
|---|---|---|
chainIdOrName | number | string | A numeric chain ID (e.g., 1) or a chain key string (e.g., "ethereum") |
Returns
Returns the matching ChainConfig object, or undefined if no chain matches.
- When given a string, performs a direct key lookup on the
chainsrecord. - When given a number, searches through all chain values to find one with a matching
id.
Examples
import { getChain } from '@web3marketlabs/sdk'
// Look up by numeric ID
getChain(1) // { id: 1, name: 'Ethereum', ... }
getChain(11155111) // { id: 11155111, name: 'Sepolia', ... }
getChain(137) // { id: 137, name: 'Polygon', ... }
// Look up by string key
getChain('ethereum') // { id: 1, name: 'Ethereum', ... }
getChain('sepolia') // { id: 11155111, name: 'Sepolia', ... }
getChain('base') // { id: 8453, name: 'Base', ... }
// Returns undefined for unknown chains
getChain(999999) // undefined
getChain('unknown') // undefinedSource
Defined in @web3marketlabs/sdk — src/chains.ts.