UNPKG

web3-error-helper

Version:

> 🛠️ Turn confusing Web3 errors into clear, human-friendly messages for developers and users alike.

270 lines (269 loc) 9.9 kB
"use strict"; /** * Chain registry - single source of truth for blockchain data * * This module serves as the centralized data store for all built-in blockchain * network configurations. It contains comprehensive metadata, error category * configurations, and chain-specific settings. Provides the foundation for * chain validation, discovery, and error mapping across the entire library. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CHAIN_REGISTRY = void 0; exports.getSupportedChainIds = getSupportedChainIds; exports.getChainConfig = getChainConfig; exports.getChainMetadata = getChainMetadata; exports.getChainErrorCategories = getChainErrorCategories; exports.getEnabledErrorCategories = getEnabledErrorCategories; exports.getAllChainConfigs = getAllChainConfigs; exports.isChainSupported = isChainSupported; const types_1 = require("../types"); /** * Chain registry data */ exports.CHAIN_REGISTRY = { [types_1.SupportedChain.ETHEREUM]: { id: types_1.SupportedChain.ETHEREUM, metadata: { name: 'Ethereum', symbol: 'ETH', chainId: 1, rpcUrls: ['https://mainnet.infura.io/v3/', 'https://eth-mainnet.alchemyapi.io/v2/'], blockExplorerUrls: ['https://etherscan.io'], nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.POLYGON]: { id: types_1.SupportedChain.POLYGON, metadata: { name: 'Polygon', symbol: 'MATIC', chainId: 137, rpcUrls: ['https://polygon-rpc.com', 'https://rpc-mainnet.maticvigil.com'], blockExplorerUrls: ['https://polygonscan.com'], nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.ARBITRUM]: { id: types_1.SupportedChain.ARBITRUM, metadata: { name: 'Arbitrum One', symbol: 'ETH', chainId: 42161, rpcUrls: ['https://arb1.arbitrum.io/rpc'], blockExplorerUrls: ['https://arbiscan.io'], nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.OPTIMISM]: { id: types_1.SupportedChain.OPTIMISM, metadata: { name: 'Optimism', symbol: 'ETH', chainId: 10, rpcUrls: ['https://mainnet.optimism.io'], blockExplorerUrls: ['https://optimistic.etherscan.io'], nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.BSC]: { id: types_1.SupportedChain.BSC, metadata: { name: 'Binance Smart Chain', symbol: 'BNB', chainId: 56, rpcUrls: ['https://bsc-dataseed.binance.org'], blockExplorerUrls: ['https://bscscan.com'], nativeCurrency: { name: 'BNB', symbol: 'BNB', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.AVALANCHE]: { id: types_1.SupportedChain.AVALANCHE, metadata: { name: 'Avalanche C-Chain', symbol: 'AVAX', chainId: 43114, rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'], blockExplorerUrls: ['https://snowtrace.io'], nativeCurrency: { name: 'Avalanche', symbol: 'AVAX', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.FANTOM]: { id: types_1.SupportedChain.FANTOM, metadata: { name: 'Fantom Opera', symbol: 'FTM', chainId: 250, rpcUrls: ['https://rpc.ftm.tools'], blockExplorerUrls: ['https://ftmscan.com'], nativeCurrency: { name: 'Fantom', symbol: 'FTM', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] }, [types_1.SupportedChain.BASE]: { id: types_1.SupportedChain.BASE, metadata: { name: 'Base', symbol: 'ETH', chainId: 8453, rpcUrls: ['https://mainnet.base.org'], blockExplorerUrls: ['https://basescan.org'], nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, isTestnet: false }, errorCategories: [ { category: 'erc20', priority: 10, enabled: true }, { category: 'gas', priority: 9, enabled: true }, { category: 'wallet', priority: 8, enabled: true }, { category: 'network', priority: 7, enabled: true }, { category: 'transaction', priority: 6, enabled: true }, { category: 'evm', priority: 5, enabled: true }, { category: 'contract', priority: 4, enabled: true } ] } }; /** * Get all supported chain identifiers */ function getSupportedChainIds() { return Object.values(types_1.SupportedChain); } /** * Get chain configuration by ID */ function getChainConfig(chainId) { return exports.CHAIN_REGISTRY[chainId]; } /** * Get chain metadata by ID */ function getChainMetadata(chainId) { return exports.CHAIN_REGISTRY[chainId]?.metadata; } /** * Get error categories for a chain */ function getChainErrorCategories(chainId) { return exports.CHAIN_REGISTRY[chainId]?.errorCategories || []; } /** * Get enabled error categories for a chain (sorted by priority) */ function getEnabledErrorCategories(chainId) { const categories = getChainErrorCategories(chainId); return categories .filter(cat => cat.enabled) .sort((a, b) => b.priority - a.priority); } /** * Get all chain configurations */ function getAllChainConfigs() { return { ...exports.CHAIN_REGISTRY }; } /** * Check if a chain is supported */ function isChainSupported(chainId) { return Object.values(types_1.SupportedChain).includes(chainId); }