I have a contract which deploys other contracts by bytecode:
contract DeployContract {
function deploy(bytes calldata _bytecode) external returns(address addr) {
bytes memory bytecode = abi.encode(_bytecode, msg.sender);
assembly {
addr := create(0, add(bytecode, 0x20), mload(bytecode))
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
}
}
I want to deploy contracts which take an address as argument in their constructor. Appending the address to the bytecode as above does not work. How do I pass the constructor parameter?
Best Answer
This worked for CREATE2. Maybe it also works on CREATE?
Example (CREATE2)