How to deploy a bytecode via Nick's factory using ethers?

86 Views Asked by At

I am trying to deploy a smart contract using Nick's factory, deployed on many EVM-compatible chains at address 0x4e59b44847b379578588920ca78fbf26c0b4956c. I tried many approach but all failed, because the deployed code was empty. How can I deploy it using Ethers or Web3? This is one of my attempts, using Ethers:

async deployContractViaNickSFactory(deployer, contractBytecode, salt) {
    const factoryContract = new this.ethers.Contract(
      "0x4e59b44847b379578588920ca78fbf26c0b4956c",
      ["function deploy(bytes _bytecode, bytes32 _salt) public returns (address)"],
      deployer
    );
    const tx = await factoryContract.deploy(contractBytecode, salt);
    await tx.wait();
    return this.ethers.utils.getCreate2Address(
        "0x4e59b44847b379578588920ca78fbf26c0b4956c",
        salt,
        this.ethers.utils.keccak256(contractBytecode)
      );
});

I could not find any source code of the original contract but I suspect that there is no deploy method there, and that would explain why that fail.

UPDATE: I found how to do it. Basically, you should send a transaction to the Nick Factory address with data field equal to salt + bytecode. I tested it and it works fine.

0

There are 0 best solutions below