1

UPDATE: I think the real question is what to use as Init code? The contract has no constructor. Can someone help on this?

Basically i am using openzeppelin Clones.sol contract to determine the deployed contract address(using implementation and the contract address that launches the contract) https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Clones.sol

I want to do the same thing on the client-side using etherJS. Apparently getCreate2Address does the same thing in js as create2 does in solidity. HOWEVER i am unable to get it to work. I verified that the salt generated is CORRECT(same as in contract), but i get different address from the one in the smart contract.

For init code, i copied the input created during the generation of the implementation contract(the one we are copying). For fromAddress i use the contract that launches the proxy contract.

The generated contractAddress in etherjs DOES NOT match the one in solidity :( What could i possibly be doing wrong? I am getting desperate at this point and have no clue how to resolve the issue.

Apparently the "initCode" should be the bytecode + concatenated constructor arguments (My contract has no arguments, so i just use the bytecode as initCode. Is this correct?

Am i inputting wrong init code? Because i don't know where else the problem could be. The salt generated in etherjs matches the solidity one, but the contract generated does not. Big F.

init code

let userWallet = "myWallet" //user wallet address
let specificId = 0
let fromAddress = "contract that launches the proxy" //MAIN CONTRACT
let salt = ethers.utils.solidityKeccak256(["bytes", "uint256", "address"], [ethers.utils.hexZeroPad(ethers.utils.hexlify(1), 1), specificId, userWallet])
let initCode = "initCodeHere"
let initCodeHash = ethers.utils.keccak256(initCode); //initcode should be bytecode
let contractAddress = ethers.utils.getCreate2Address(fromAddress, salt, initCodeHash);

console.log("SALT WORKS" + salt)
console.log(contractAddress)

0

Your Answer

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

Browse other questions tagged or ask your own question.