2

I know a smart contract can deploy another contract if both contracts are in scope of the same file. I'm wondering if I can write a contract that has its own deployBytecode() function. You would call the deployBytecode() function and pass in the bytecode, and the existing smart contract would create that contract.

Is this possible yet?

4

Yes, you're looking for create. Something like this:

function deploy(bytes _bytecode) external returns (address) {
    address addr;
    bytes memory bytecode = _bytecode;

    assembly {
        addr := create(0, add(bytecode, 0x20), mload(bytecode))
    }

    return addr;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.