Given that our product is designed to be multi-chain, it would be very convenient for users and developers if the same contracts were deployed on the same addresses across different chains. The address of an EVM smart contract is computed deterministically, with two variables: the caller (msg.sender) and the nonce (the transaction # of the msg.sender). So, for example, if a wallet's 39th transaction on 7 different chains is launching CrafterTransfer.sol, that instance of CrafterTransfer.sol will have the same address across all those chains.
Because it is so easy to mess this up, we want to make 2 checks
We want to ensure that the wallet is at the right nonce before sending the launch-contract transaction.
And we want to ensure that it is launching at the right address
Implementation
Our deploying wallet address is 0x6fd935c3BbbDf664b67e28B14236a66a7588D683. It is currently at nonce 17. So, inside the 001_Implementation folder, simply set the first contract's nonceToDeploy to 17 (skip the ProxyFactory though because we don't need to re-deploy that one. ) And the next one to 18, etc... And any time a new Implementation deploy script is added, just give it the next nonce. This isn't needed for non-Implementation scripts.
Verifying the address is slightly longer process. Use the private key for 0x6fd935c3BbbDf664b67e28B14236a66a7588D683 as your first account in the hardhat config. If you're running the deploy scripts on hardhat network, the scripts will auto burn nonces until the right nonce is reached. You just have to make sure that they are running in order. So now you have the same contracts deploying on an EVM network with the same msg.sender and the same nonce. So the address you get is what we will get on other EVM chains as well.
Description
Given that our product is designed to be multi-chain, it would be very convenient for users and developers if the same contracts were deployed on the same addresses across different chains. The address of an EVM smart contract is computed deterministically, with two variables: the caller (
msg.sender
) and the nonce (the transaction # of the msg.sender). So, for example, if a wallet's 39th transaction on 7 different chains is launchingCrafterTransfer.sol
, that instance ofCrafterTransfer.sol
will have the same address across all those chains.Because it is so easy to mess this up, we want to make 2 checks
Implementation
Our deploying wallet address is 0x6fd935c3BbbDf664b67e28B14236a66a7588D683. It is currently at nonce 17. So, inside the
001_Implementation
folder, simply set the first contract'snonceToDeploy
to 17 (skip theProxyFactory
though because we don't need to re-deploy that one. ) And the next one to 18, etc... And any time a new Implementation deploy script is added, just give it the next nonce. This isn't needed for non-Implementation scripts.Verifying the address is slightly longer process. Use the private key for 0x6fd935c3BbbDf664b67e28B14236a66a7588D683 as your first account in the hardhat config. If you're running the deploy scripts on
hardhat
network, the scripts will auto burn nonces until the right nonce is reached. You just have to make sure that they are running in order. So now you have the same contracts deploying on an EVM network with the samemsg.sender
and the same nonce. So the address you get is what we will get on other EVM chains as well.