2

I have noticed by doing some tests that when I publish the same contract on different networks, the address is the same. Then, the "Etherscan" of each network show a link to blockscan.com where it show all the EVM networks with the same address.

But I can't find the pattern of how it happens...

How could deploy a contract in several EVM networks with the certainty that all will have the same address?

4 Answers 4

1

A full answer to this question should detail the difference between CREATE, CREATE2 opcodes, which are the two opcodes in the EVM for creating new contracts; it should be possible to do this using either as long as for CREATE you use the same keypair across all chains, and have the same nonce on all chains. This article also details how to use CREATE2 for the same task (provided initcode is consistent across all chains), which should be easier, all things considered. I'm going to gloss over that all because of CREATE3, though.

There has been some work recently nicknamed CREATE3. This isn't an actual opcode in the EVM (yet), but rather some work done to make contracts which are themselves contract factories which make it a bit easier to deterministically generate addresses. The first implementation I'm aware of is 0xsequence's here, though Rari also ships an implementation in Solmate.

There is a README in 0xsequence's repo explaining how to use the contract. The basic uptake would be that you could import this library, and as long as the contract bytecode is identical across all chains, just using the same salt in the create3 function (or deploy in Solmate) should ensure that the address of all deployments is identical.

4
  • Thank you for your comment, but I did not understand anything. I deployed contracts in several EMV blockchains and had the same address without i did nothing special. I don't know if this happens if I first upload the contract to Ethereum and then the others copy it. Or if it must be verified ... It is difficult to test when uploading a contract to Ethereum costs more than $ 300 Jan 2, 2022 at 20:30
  • How were you deploying the contracts? Jan 3, 2022 at 6:49
  • I use Remix to deploy my contracts Jan 3, 2022 at 11:29
  • In that particular case it is going to be difficult. Essentially, if you are using wallets that have the exact same nonce on each chain that you deploy on, I think it should work out. (See answer for why.) This is hard to coordinate. I would recommend learning to use a dev environment like Hardhat and to work with create2, or even use a create3 instance. Jan 9, 2022 at 14:10
1

Your contracts will also have the same address if you deploy them with the same nonce. Let's say you take a fresh wallet that has 0 transactions in it. And you use the very first transaction in each network to deploy your contract, then you will also have the same contract addresses across all networks. Incoming transactions do not use a nonce, so you can send some ETH or whatever to that fresh wallet to fund the deployment. But do nothing else with it...just deploy. Then you will have same addresses.

0

You can do this with CREATE2, and there are at least two tools that I know of that you can use to deploy contracts at deterministic addresses on multiple chains:

  1. Zoltu/deterministic-deployment-proxy (also Arachnid's fork if you need salts)
  2. pcaversaccio/xdeployer
0

Simple answer: Create a new clean wallet, and use its private key to deploy the contract.

This will work because;

contractAddress = keccak256(userAddress, nonce);
// NOTE: nonce is the number of transactions done by userAddress.
 

Becasue your wallet is new, and hasn't done any previous transactions, your nonce will be zero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.