Function Signature
Parameters
Array of Chain structs to apply overrides to. Typically obtained from
GetChains(), GetMainnetChains(), or GetTestnetChains()Map where keys are chain names and values are the override RPC URLs. Use chain name constants for type safety (e.g.,
cctp.Ethereum, cctp.Arbitrum)Returns
A new array of Chain structs with RPC URLs overridden where specified. The original chains slice is not mutated.Behavior:
- Matching chain names have their RPC field replaced with the override URL
- Empty string overrides are ignored (original RPC is preserved)
- Non-matching chain names are ignored
- Chains without overrides retain their default RPC URLs
- If overrides map is empty, returns the original chains unchanged
Usage Example
Basic Override
Full Example from README
Configuration-based Overrides
Testnet Overrides
Available Chain Constants
Mainnet
cctp.Ethereum, cctp.Avalanche, cctp.OPMainnet, cctp.Arbitrum, cctp.Base, cctp.PolygonPoS, cctp.Unichain, cctp.Linea, cctp.Codex, cctp.Sonic, cctp.WorldChain, cctp.Sei, cctp.XDC, cctp.HyperEVM, cctp.Ink, cctp.Plume
Testnet
cctp.EthereumSepolia, cctp.AvalancheFuji, cctp.OPSepolia, cctp.ArbitrumSepolia, cctp.BaseSepolia, cctp.PolygonPoSAmoy, cctp.LineaSepolia, cctp.ArcTestnet, cctp.UnichainSepolia, cctp.CodexTestnet, cctp.SonicTestnet, cctp.WorldChainSepolia, cctp.SeiTestnet, cctp.XDCApothem, cctp.HyperEVMTestnet, cctp.InkTestnet, cctp.PlumeTestnet
Important Notes
Immutability: The original chains slice is not mutated. The function returns a new slice with the overrides applied.
Empty Overrides: Empty string overrides are ignored, preserving the original RPC URL for that chain.
Type Safety: Use the chain name constants (e.g.,
cctp.Ethereum) for IDE autocomplete support and to avoid typos. String literals are still supported but must match exactly (case-sensitive).No-op Behavior: If the overrides map is empty, the function returns the original chains unchanged.
Best Practices
- Use constants: Always use chain name constants for map keys to prevent typos
- Environment-based: Load RPC URLs from environment variables or configuration files
- Validation: Validate RPC URLs before passing them to this function
- Fallback: The default RPC URLs are always available as fallbacks
- Security: Never hardcode API keys; use environment variables or secure configuration
Related Functions
- GetChains - Get all configured chains
- GetChainByDomain - Find a specific chain by its domain ID
- GetChainByName - Find a specific chain by its name