6.4 Post-Deployment Configuration (setPeers)
After all TokenFactory contracts are deployed, you must link them together so they trust each other. This involves calling setPeer(uint32 chainId, address peerAddress)
on each factory for each other chain.
The chain IDs are LayerZero’s chain IDs (not EVM chain IDs). For reference:
-
Ethereum mainnet = LayerZero chain ID 1
-
BSC = 56
-
Avalanche = 43114
-
Arbitrum = 42161
-
Base = 8453
(These are the standard LayerZero IDs for mainnets).
You can use Foundry’s
cast
or write a small script to do this. For illustration, using
cast
:
-
On Ethereum factory, set peers:
cast send <EthFactoryAddress> "setPeer(uint32,address)" 56 <BSCFactoryAddress> --rpc-url $ETH_RPC_URL --private-key $PRIVATE_KEY
cast send <EthFactoryAddress> "setPeer(uint32,address)" 43114 <AvaxFactoryAddress> --rpc-url $ETH_RPC_URL --private-key $PRIVATE_KEY
cast send <EthFactoryAddress> "setPeer(uint32,address)" 42161 <ArbFactoryAddress> --rpc-url $ETH_RPC_URL --private-key $PRIVATE_KEY
cast send <EthFactoryAddress> "setPeer(uint32,address)" 8453 <BaseFactoryAddress> --rpc-url $ETH_RPC_URL --private-key $PRIVATE_KEY
-
On BSC factory, set peers for Eth, Avax, Arb, Base (with BSC’s RPC and so on).
-
Repeat for Avalanche, Arbitrum, Base.
Each transaction will cost a bit of gas. Double-check the addresses and chain IDs – a mistake here could route messages incorrectly. You might also have a dedicated script to loop through an array of known addresses and call setPeer for each combination.
After this, each TokenFactory has the addresses of its siblings. They will use these in cross-chain message verification.
6.5 Verification (Optional)