2

Is there any way to calculate the deterministic address of a contract cloned by a Factory through create2?

I have this contract Factory

contract ForwarderFactory {
function cloneForwarder(address payable forwarder, uint256 salt)
    public
    returns (Forwarder clonedForwarder)
{
    address payable clonedAddress = createClone(forwarder, salt);
    clonedForwarder = Forwarder(clonedAddress);
    clonedForwarder.init(Forwarder(forwarder).owner());
    emit Deployed(clonedAddress, msg.sender);
}

function createClone(address payable target, uint256 salt)
    private
    returns (address payable result)
{
    bytes20 targetBytes = bytes20(target);
    assembly {
        let clone := mload(0x40)
        mstore(
            clone,
            0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
        )
        mstore(add(clone, 0x14), targetBytes)
        mstore(
            add(clone, 0x28),
            0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
        )
        result := create2(0, clone, 0x37, salt)
    }
}

}

How can I know before creating the clone which address will it have?

  • This answer includes the formula at the bottom https://ethereum.stackexchange.com/a/761. – Ismael Aug 27 '20 at 06:36
  • 1
    I have the same question @Gustavo, did you manage to calculate this address? – Franco May 31 '21 at 13:48
  • Yes man, i solved this. This is what you are lookin for https://forum.openzeppelin.com/t/how-to-compute-the-create2-address-for-a-minimal-proxy/3595

    Any questions my inbox is open

    – Gustavo Toledo Jun 03 '21 at 02:25

0 Answers0