Here I have a function which deploys a Contract straight from bytecode, but let say my contract needs some arguments in the constructor, is it possible to pass them through create opcode?

function deployCode(bytes _code) returns (address deployedAddress) {
    assembly {
        deployedAddress := create(0, add(_code, 0x20), mload(_code))
        jumpi(invalidJumpLabel, iszero(extcodesize(deployedAddress)))
    return deployedAddress

Constructor arguments are appended to the deployment byte code in the standard ABI format.

For example, this contract takes uint constructor argument.

contract Foo {
    uint a;
    function Foo(uint _a) public {
        a = _a;

It compiles to the following deployment bytecode:


If we want to pass the value 42 (0x2a) to the constructor then we append the 32-byte ABI version of 0x2a to the bytecode that we give to the CREATE operation. The constructor knows where to find it. I.e. Pass this to CREATE:


When the contract is CREATEd, its storage will be immediately populated with 42.

This is exactly the same as passing constructor parameters when creating a contract from an Externally Owned Account.

  • 2
    You made my day! – AirUp Mar 21 '19 at 20:16

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.