// Network configuration data
export interface NetworkConfig {
rpcUrl: string
chainId: number
name: string
currency: string
explorerUrl: string
}
// Default network configurations
const NETWORK_CONFIGS: Record<string, NetworkConfig> = {
ethereum: {
rpcUrl: "https://eth.public-rpc.com",
chainId: 1,
name: "Ethereum Mainnet",
currency: "ETH",
explorerUrl: "https://etherscan.io"
},
sepolia: {
rpcUrl: "https://sepolia.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
chainId: 11155111,
name: "Sepolia Testnet",
currency: "ETH",
explorerUrl: "https://sepolia.etherscan.io"
},
polygon: {
rpcUrl: "https://polygon-rpc.com",
chainId: 137,
name: "Polygon Mainnet",
currency: "MATIC",
explorerUrl: "https://polygonscan.com"
},
mumbai: {
rpcUrl: "https://rpc-mumbai.maticvigil.com",
chainId: 80001,
name: "Polygon Mumbai",
currency: "MATIC",
explorerUrl: "https://mumbai.polygonscan.com"
},
bsc: {
rpcUrl: "https://bsc-dataseed.binance.org",
chainId: 56,
name: "BNB Smart Chain",
currency: "BNB",
explorerUrl: "https://bscscan.com"
},
avalanche: {
rpcUrl: "https://api.avax.network/ext/bc/C/rpc",
chainId: 43114,
name: "Avalanche C-Chain",
currency: "AVAX",
explorerUrl: "https://snowtrace.io"
},
arbitrum: {
rpcUrl: "https://arb1.arbitrum.io/rpc",
chainId: 42161,
name: "Arbitrum One",
currency: "ETH",
explorerUrl: "https://arbiscan.io"
},
optimism: {
rpcUrl: "https://mainnet.optimism.io",
chainId: 10,
name: "Optimism",
currency: "ETH",
explorerUrl: "https://optimistic.etherscan.io"
}
}
/**
* Get network configuration by name
*/
export function getNetworkConfig(network: string): NetworkConfig {
const config = NETWORK_CONFIGS[network.toLowerCase()]
if (!config) {
throw new Error(`Unsupported network: ${network}. Available networks: ${Object.keys(NETWORK_CONFIGS).join(", ")}`)
}
return config
}
/**
* Get all available networks
*/
export function getAvailableNetworks(): string[] {
return Object.keys(NETWORK_CONFIGS)
}
/**
* Check if network is supported
*/
export function isNetworkSupported(network: string): boolean {
return network.toLowerCase() in NETWORK_CONFIGS
}