Package: @web3marketlabs/sdkChains

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

KeyIDNameNative CurrencySymbolTestnet
anvil31337AnvilEtherETHYes
ethereum1EthereumEtherETHNo
sepolia11155111SepoliaSepolia EtherETHYes
arbitrum42161Arbitrum OneEtherETHNo
arbitrumSepolia421614Arbitrum SepoliaEtherETHYes
base8453BaseEtherETHNo
baseSepolia84532Base SepoliaEtherETHYes
polygon137PolygonPOLPOLNo
polygonAmoy80002Polygon AmoyPOLPOLYes
optimism10OptimismEtherETHNo
optimismSepolia11155420Optimism SepoliaEtherETHYes

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

ChainDefault RPC URL
Anvilhttp://127.0.0.1:8545
Ethereumhttps://eth.llamarpc.com
Sepoliahttps://rpc.sepolia.org
Arbitrum Onehttps://arb1.arbitrum.io/rpc
Arbitrum Sepoliahttps://sepolia-rollup.arbitrum.io/rpc
Basehttps://mainnet.base.org
Base Sepoliahttps://sepolia.base.org
Polygonhttps://polygon-rpc.com
Polygon Amoyhttps://rpc-amoy.polygon.technology
Optimismhttps://mainnet.optimism.io
Optimism Sepoliahttps://sepolia.optimism.io

getChain(chainIdOrName)

Look up a chain by its numeric chain ID or string key name.

function getChain(chainIdOrName: number | string): ChainConfig | undefined

Parameters

ParameterTypeDescription
chainIdOrNamenumber | stringA 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 chains record.
  • 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')    // undefined

Source

Defined in @web3marketlabs/sdksrc/chains.ts.