2

I would like to deploy the same contract to multiple chains under the same address using CREATE2.

DeterministicDeployFactory: https://docs.alchemy.com/docs/create2-an-alternative-to-deriving-contract-addresses

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract DeterministicDeployFactory {
    event Deploy(address addr);

    function deploy(bytes memory bytecode, uint _salt) external {
        address addr;
        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
            if iszero(extcodesize(addr)) {
        revert(0, 0)
      }
    }

    emit Deploy(addr);
    }
}

🟩 Sepolia: https://sepolia.etherscan.io/address/0x3311fff00a0b7553f127b5b25397e12cb268f919#code

🟦 Goerli: https://goerli.etherscan.io/address/0x34d32ac4ed0cef66bbc638781b97fa6b494b98e0#code

Then, I've compiled a simple contract storage.sol, the default contract when opening Remix IDE.

The bytecode: 0x608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100a1565b60405180910390f35b610073600480360381019061006e91906100ed565b61007e565b005b60008054905090565b8060008190555050565b6000819050919050565b61009b81610088565b82525050565b60006020820190506100b66000830184610092565b92915050565b600080fd5b6100ca81610088565b81146100d557600080fd5b50565b6000813590506100e7816100c1565b92915050565b600060208284031215610103576101026100bc565b5b6000610111848285016100d8565b9150509291505056fea2646970667358221220522334dfd7decc643eeb644e28d6d7f11bae5f5b74d14e33980a35d12bc7771f64736f6c63430008110033

Salt: 17

🟩 Sepolia deploy TX: https://sepolia.etherscan.io/tx/0xdbe937835979c53b840a5737fe65b9ab93368ff53275e4787cf3ef73fe533a1a

🟩 Sepolia deployed storage: https://sepolia.etherscan.io/address/0x8C4201833590b5F93c813847b24902bFf7131FDF

🟦 Goerli deploy TX: https://goerli.etherscan.io/tx/0x4c92195afbfca1630e9d7f73ca13e190e36c19d5d8eff8397d9e4d7b1b104a82

🟦 Goerli deployed storage: https://goerli.etherscan.io/address/0xB38f04cb936E19AB9B8F09b15122668c1F9f77e3


I do not understand the reason why the deployed address on Sepolia is different than on Goerli.

enter image description here

enter image description here

The DeterministicDeployFactory bytecode and salt are the same...

SOLVED

🟦 Factory: https://goerli.etherscan.io/address/0x1dd764cf61c8e56ea048374fece83ffa40616569#code

🟩 Factory https://sepolia.etherscan.io/address/0x1dd764cf61c8e56ea048374fece83ffa40616569

🟦 Storage: https://goerli.etherscan.io/address/0x8bB256467BfE67b8add96002ffe1B05350bFfA57#code

🟩 Storage: https://sepolia.etherscan.io/address/0x8bB256467BfE67b8add96002ffe1B05350bFfA57#code

1 Answer 1

2

Deterministic contract address depends upon the factory contract address. In your case, the contract address of DeterministicDeployFactory. If the value of DeterministicDeployFactory is same in all other chain and of course the smart contract of diterministic contract will be same.

6
  • Sounds like an egg-chicken problem... How would you solve it? How would you deploy the factory to the same address? Commented Feb 20, 2023 at 16:08
  • Only solution I think is first you have to do some transactions in all networks so that the next nonce that your wallet will have x in all network, with that nonce and bytecode you can get same address for DeterministicDeployFactory.
    – Safi
    Commented Feb 20, 2023 at 16:19
  • For more detail you check this docs.alchemy.com/docs/…
    – Safi
    Commented Feb 20, 2023 at 16:20
  • Thank you for all your comments and support. I recognize that link, I've included part 2 in my original question. Manually managing nonces does not seem practical. Pretty sure there is a way... Commented Feb 20, 2023 at 16:47
  • Yes, just create a new wallet and use it for just the deployment of your factory contract in all chain.
    – Safi
    Commented Feb 20, 2023 at 17:13

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.