Add CCIP Networks for Cross-Chain Token Tutorials (Foundry)
Guide Versions
This guide is available in multiple versions. Choose the one that matches your needs.
The smart-contract-examples repository includes default configurations for common CCIP testnet networks. This guide shows how to add support for additional networks.
Add a Network
Add the network configuration to script/HelperConfig.s.sol
// Rest of the code...
constructor() {
// Rest of the existing networks...
else if (block.chainid == 11155420) {
activeNetworkConfig = getOptimismSepoliaConfig();
} else {
revert("Unsupported network");
}
}
// Rest of the existing network configurations...
function getOptimismSepoliaConfig() public pure returns (NetworkConfig memory) {
NetworkConfig memory optimismSepoliaConfig = NetworkConfig({
chainSelector: 5224473277236331295,
router: 0x114A20A10b43D4115e5aeef7345a1A71d2a60C57,
rmnProxy: 0xb40A3109075965cc09E93719e33E748abf680dAe,
tokenAdminRegistry: 0x1d702b1FA12F347f0921C722f9D9166F00DEB67A,
registryModuleOwnerCustom: 0x49c4ba01dc6F5090f9df43Ab8F79449Db91A0CBB,
link: 0xE4aB69C077896252FAFBD49EFD26B5D171A32410,
confirmations: 2,
nativeCurrencySymbol: "ETH"
});
return optimismSepoliaConfig;
}
function getNetworkConfig(uint256 chainId) public pure returns (NetworkConfig memory) {
// Rest of the existing networks...
else if (chainId == 11155420) {
return getOptimismSepoliaConfig();
} else {
revert("Unsupported chain ID");
}
}
Set the RPC URL:
RPC_URL_OPTIMISM_SEPOLIA="INSERT_YOUR_RPC_URL_HERE"
Save the .env file, then load the environment variable into the terminal session:
source .env
The network is now available in all Foundry commands using --rpc-url $RPC_URL_OPTIMISM_SEPOLIA.
Configuration Fields
| Field | Required | Description | Source |
|---|---|---|---|
chainSelector | Yes | CCIP identifier for the network | CCIP Directory |
router | Yes | CCIP Router contract address | CCIP Directory |
rmnProxy | Yes | RMN Proxy contract address | CCIP Directory |
tokenAdminRegistry | Yes | Token Admin Registry address | CCIP Directory |
registryModuleOwnerCustom | Yes | Registry Module Owner address | CCIP Directory |
link | Yes | LINK token contract address | CCIP Directory |
confirmations | No | Number of block confirmations before considering transaction final | Blockchain's finality characteristics and your risk tolerance |
nativeCurrencySymbol | No | Native gas token symbol (e.g., "ETH", "AVAX", "POL") | Blockchain's official documentation |
Find all CCIP addresses in the CCIP Directory - Testnet or CCIP Directory - Mainnet.
Test
Deploy a token to verify the configuration:
forge script script/DeployToken.s.sol --rpc-url $RPC_URL_OPTIMISM_SEPOLIA --private-key $PRIVATE_KEY --broadcast
Contract Verification (Optional)
Most networks are natively supported. Add --verify when deploying:
forge script script/DeployToken.s.sol --rpc-url $RPC_URL_OPTIMISM_SEPOLIA --private-key $PRIVATE_KEY --broadcast --verify
For networks not in Foundry's StdChains.sol::StdChains::initializeStdChains() function, include the --verifier, --verifier-url, and --verifier-api-key flags together with --verify when deploying:
forge script script/DeployToken.s.sol --rpc-url $RPC_URL_CUSTOM_NETWORK --private-key $PRIVATE_KEY --broadcast --verify --verifier custom --verifier-url $CUSTOM_EXPLORER_API_URL --verifier-api-key $CUSTOM_EXPLORER_API_KEY
With Etherscan API V2, a single ETHERSCAN_API_KEY works across all Etherscan-compatible networks.