Function Signature
Parameters
The chain name to search for. Must match exactly (case-sensitive). Use the chain name constants from the SDK for type safety (e.g.,
cctp.Ethereum, cctp.Arbitrum)Set to
true to search testnet chains, or false to search mainnet chainsReturns
Pointer to a Chain struct containing the blockchain configuration, or
nil if not found. The Chain includes:Name(string) - Chain nameChainID(*big.Int) - EVM chain IDDomain(uint32) - CCTP domain identifierRPC(string) - Default RPC endpoint URLTokenMessengerV2(string) - TokenMessenger V2 contract addressMessageTransmitterV2(string) - MessageTransmitter V2 contract addressUSDC(string) - USDC token contract addressExplorer(string) - Block explorer URLIsTestnet(bool) - Whether this is a testnet chainInstantFinality(bool) - Whether the chain has instant finality
Error if the chain with the specified name is not found. Returns
nil if successful.Usage Example
Chain Name Constants
Use these constants for type-safe chain name references:Mainnet
Testnet
Chain names are case-sensitive and must match exactly. Using the provided constants is recommended to avoid typos and enable IDE autocomplete.
Error Handling
The function returns an error with the message"chain %s not found" if no chain matches the specified name.
Best Practices
- Use constants: Always use the chain name constants (e.g.,
cctp.Ethereum) instead of string literals - IDE autocomplete: Constants provide autocomplete support in most IDEs
- Type safety: Constants prevent typos and ensure valid chain names
- Case sensitivity: If using string literals, ensure exact case matching
Related Functions
- GetChains - Get all configured chains
- GetChainByDomain - Find a specific chain by its domain ID
- ApplyRPCOverrides - Override default RPC endpoints