You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Configure Additional Networks using Foundry"
5
5
metadata:
6
6
description: "Learn how to configure additional networks in the smart-contract-examples repository to add support for more CCIP-supported chains using Foundry."
When working with the [smart-contract-examples](https://github.com/smartcontractkit/smart-contract-examples/tree/main/ccip/cct) CCIP tutorials, you may need to add support for additional blockchain networks beyond the default testnet configurations (_Avalanche Fuji_, _Ethereum Sepolia_, _Arbitrum Sepolia_, _Base Sepolia_, and _Polygon Amoy_). This guide explains how to update the network configuration files in the Foundry version of the repository.
32
+
When working with the [smart-contract-examples](https://github.com/smartcontractkit/smart-contract-examples/tree/main/ccip/cct) CCIP tutorials, you may need to add support for additional blockchain networks beyond the default testnet configurations (_Avalanche Fuji_, _Ethereum Sepolia_, _Arbitrum Sepolia_, and _Base Sepolia_, and _Polygon Amoy_).
33
33
34
-
## Overview
34
+
This guide explains how to update the network configuration file in the [Foundry version of the repository](https://github.com/smartcontractkit/smart-contract-examples/tree/main/ccip/cct/foundry). The configuration file stores network-specific information such as:
35
35
36
-
The [smart-contract-examples](https://github.com/smartcontractkit/smart-contract-examples/tree/main/ccip/cct/foundry) repository includes pre-configured network settings for common CCIP testnets. These configuration files store network-specific information such as:
37
-
38
-
- Chain selectors
36
+
- Chain selectors (unique CCIP identifiers)
39
37
- Router addresses
40
38
- RMN Proxy addresses
41
39
- Token Admin Registry addresses
@@ -44,17 +42,9 @@ The [smart-contract-examples](https://github.com/smartcontractkit/smart-contract
44
42
- Block confirmations
45
43
- Native currency symbols
46
44
47
-
**Default networks included**:
48
-
49
-
- Avalanche Fuji
50
-
- Ethereum Sepolia
51
-
- Arbitrum Sepolia
52
-
- Base Sepolia
53
-
- Polygon Amoy
45
+
These values vary by network and must be accurate for your CCIP transactions to work correctly. If you want to use additional networks (e.g., Optimism Sepolia, BNB Chain Testnet, or mainnet networks) supported by CCIP, you'll need to update the configuration file following this guide.
54
46
55
-
These values vary by network and must be accurate for your CCIP transactions to work correctly. If you want to use additional networks (e.g., Optimism Sepolia, BNB Chain Testnet, or mainnet networks), you'll need to update the configuration files following this guide.
56
-
57
-
## Finding Network Configuration Values
47
+
## Find Network Configuration Values
58
48
59
49
All CCIP-supported networks and their configuration details are available in the **CCIP Directory**:
60
50
@@ -63,7 +53,7 @@ All CCIP-supported networks and their configuration details are available in the
63
53
64
54
The CCIP Directory provides:
65
55
66
-
- Chain selectors
56
+
- Chain selectors (unique CCIP identifiers)
67
57
- Router contract addresses
68
58
- RMN Proxy addresses
69
59
- Token Admin Registry addresses
@@ -75,9 +65,27 @@ The CCIP Directory provides:
75
65
incorrect addresses or chain selectors will cause your transactions to fail.
76
66
</Aside>
77
67
78
-
## Updating Configuration Files
68
+
## Add `RPC_URL` Environment Variable
69
+
70
+
To add support for additional networks, you need to configure the `RPC_URL_<NEW_NETWORK_NAME>` environment variable in your `.env` file. This variable should point to the RPC endpoint of the network you want to add.
71
+
72
+
1. Open the `.env` file in the root of [`smart-contract-examples/ccip/cct/foundry`](https://github.com/smartcontractkit/smart-contract-examples/tree/main/ccip/cct/foundry).
73
+
74
+
2. Add a new line for the `RPC_URL_<NEW_NETWORK_NAME>` variable:
In the smart-contract-examples repository, Foundry projects store network configuration in `script/HelperConfig.s.sol`.
80
+
You can obtain an RPC URL by signing up for a personal endpoint from [Alchemy](https://www.alchemy.com/), [Infura](https://www.infura.io/), or another node provider service.
81
+
82
+
3. Save the file, then load the environment variables into the terminal session where you will run the commands:
@@ -129,7 +129,23 @@ contract HelperConfig is Script {
129
129
return avalancheFujiConfig;
130
130
}
131
131
132
-
// Add more network configurations here...
132
+
// Rest of the existing network configurations...
133
+
134
+
function getNetworkConfig(uint256 chainId) public pure returns (NetworkConfig memory) {
135
+
136
+
// Rest of the existing networks...
137
+
138
+
else if (chainId == 43113) {
139
+
return getAvalancheFujiConfig();
140
+
}
141
+
142
+
// Rest of the existing networks...
143
+
144
+
else {
145
+
revert("Unsupported chain ID");
146
+
}
147
+
}
148
+
133
149
}
134
150
```
135
151
@@ -143,7 +159,7 @@ contract HelperConfig is Script {
143
159
144
160
1. Open `script/HelperConfig.s.sol` in your preferred editor
145
161
146
-
1. Visit the [CCIP Directory](/ccip/directory/testnet) (for testnet) or [Mainnet Directory](/ccip/directory/mainnet) (for mainnet)
162
+
1. Visit the [CCIP Directory](/ccip/directory)
147
163
148
164
1. Locate your desired network in the directory and copy the following values:
149
165
- Chain Selector
@@ -153,7 +169,7 @@ contract HelperConfig is Script {
153
169
- Registry Module Owner Custom address
154
170
- LINK token address
155
171
156
-
1.Find the network's chain ID from its official documentation
172
+
1.Determine the chain ID from official network documentation, from [ChainList](https://chainlist.org/), or by running the [`cast chain-id`](https://getfoundry.sh/cast/reference/chain-id/) command.
157
173
158
174
1. Add a new condition in the `constructor()` to detect the chain ID
159
175
@@ -163,25 +179,27 @@ contract HelperConfig is Script {
163
179
-`confirmations`: Number of block confirmations to wait (typically 2-3 for testnets, 5-10 for mainnet)
164
180
-`nativeCurrencySymbol`: The native currency symbol (e.g., "ETH", "AVAX", "POL")
165
181
166
-
1. Save the file and test your configuration with a simple script
167
-
168
182
**Example: Adding Optimism Sepolia Testnet**:
169
183
170
184
```solidity
185
+
// Rest of the code...
186
+
171
187
constructor() {
172
188
if (block.chainid == 11155111) {
173
189
activeNetworkConfig = getEthereumSepoliaConfig();
174
-
} else if (block.chainid == 421614) {
175
-
activeNetworkConfig = getArbitrumSepolia();
176
-
} else if (block.chainid == 43113) {
177
-
activeNetworkConfig = getAvalancheFujiConfig();
178
-
} else if (block.chainid == 84532) {
179
-
activeNetworkConfig = getBaseSepoliaConfig();
180
-
} else if (block.chainid == 11155420) {
190
+
}
191
+
192
+
// Rest of the existing networks...
193
+
194
+
else if (block.chainid == 11155420) {
181
195
activeNetworkConfig = getOptimismSepoliaConfig();
196
+
} else {
197
+
revert("Unsupported network");
182
198
}
183
199
}
184
200
201
+
// Rest of the existing network configurations...
202
+
185
203
function getOptimismSepoliaConfig() public pure returns (NetworkConfig memory) {
**Symptom**: LINK approval or transfer operations fail
233
-
**Solution**: Verify the LINK token address for your specific network
251
+
#### Contract Verification (Optional)
234
252
235
-
### Chain ID Mismatch
253
+
**Automatic Verification (Natively Supported):**
254
+
Most standard networks are natively supported by Foundry for contract verification. Check [Foundry's `StdChains.sol::StdChains::initializeStdChains()`](https://github.com/foundry-rs/forge-std/blob/master/src/StdChains.sol#L193) function for the complete list of supported networks.
236
255
237
-
**Symptom**: Wrong network configuration is loaded
238
-
**Solution**: Check that the chain ID in the constructor matches your target network
256
+
You just need to add the `--verify` flag when deploying:
-[CCIP Directory - Testnet](/ccip/directory/testnet): Complete list of testnet networks and configuration values
243
-
-[CCIP Directory - Mainnet](/ccip/directory/mainnet): Complete list of mainnet networks and configuration values
244
-
-[Register from an EOA (Burn & Mint)](/ccip/tutorials/evm/cross-chain-tokens/register-from-eoa-burn-mint-foundry): Tutorial using these configuration files
245
-
-[Set Token Pool rate limits](/ccip/tutorials/evm/cross-chain-tokens/update-rate-limiters-foundry): Tutorial for configuring rate limiters
262
+
Or if already deployed, you can verify using the [`forge verify-contract` command](https://getfoundry.sh/forge/reference/verify-contract#forge-verify-contract).
246
263
247
-
## Adapting for Your Own Projects
264
+
<br></br>
248
265
249
-
While this guide focuses on the smart-contract-examples repository structure, you can adapt these principles for your own projects:
266
+
#### Custom Network Deployment and Verification
250
267
251
-
1.**Different project structure**: Adjust the file paths to match your project's organization
252
-
1.**Custom configuration format**: You may use environment variables, YAML, TOML, or other formats—apply the same CCIP Directory values
253
-
1.**Additional parameters**: Your project may require extra configuration fields beyond what's shown here
254
-
1.**Multiple networks**: Consider organizing configurations by environment (development, staging, production)
268
+
**Custom Network Deployment:**
269
+
For networks not natively supported by Foundry, replace the dynamic chain name lookup (`getChain(block.chainid).chainAlias`) in your deployment script with a hardcoded string, as the `getChain` call will revert on unsupported networks.
255
270
256
-
The key principle remains the same: **Always retrieve official CCIP configuration values from the [CCIP Directory](/ccip/directory)** to ensure compatibility and correctness.
Once you've updated your network configuration in the smart-contract-examples repository:
277
+
with this:
261
278
262
-
1.**Update RPC URLs**: Add the RPC URL to your `.env` file and use the environment variable as the value for the `--rpc-url` flag
279
+
```solidity
280
+
string memory chainName = "custom"; // or any other string identifier you prefer
281
+
```
263
282
264
-
1.**Fund your wallet** with native tokens and LINK for the new network using the [Chainlink faucets](https://faucets.chain.link/) (for testnets)
283
+
<br></br>
265
284
266
-
1.**Test the configuration** by running a simple deployment:
285
+
**Custom Network Verification:**
286
+
For networks not natively supported by Foundry, include the `--verifier`, `--verifier-url`, and `--verifier-api-key` flags together with `--verify` when deploying, like:
Refer to the [Foundry docs](https://getfoundry.sh/forge/reference/verify-check/) for more details.
293
+
294
+
This is particularly useful for:
295
+
- Newer networks not yet added to Hardhat
296
+
- Private/enterprise chains
297
+
- Custom testnets
298
+
299
+
**Note:** With [Etherscan API V2](https://docs.etherscan.io/introduction), a single `ETHERSCAN_API_KEY` works across all Etherscan-compatible networks.
300
+
272
301
1.**Follow the tutorials** using your newly configured network
302
+
303
+
## Adapt for Your Own Projects
304
+
305
+
While this guide focuses on the smart-contract-examples repository structure, you can adapt these principles for your own projects.
0 commit comments