Bytecode

Practical Example

Imagine that we have the following contract, which has a constructor function defined. Whenever we compile it, we will obtain the Runtime Bytecode (on Remix, you can just click on Bytecode under compilation tab, to copy it).

contract WithConstructor {
    
    uint8 public immutable a;

    constructor(uint8 _a) {
        a = _a;
    }
}

Whenever we deploy it, by passing a constructor argument of 4, we can obtain the Creation Bytecode (by looking into the Hex Data of the transaction).

Notice the difference between the Runtime Bytecode (constructor data not included) and Creation Bytecode (constructor data included) below.

Runtime Bytecode

60a060405234801561001057600080fd5b5060405161019d38038061019d83398181016040528101906100329190610084565b8060ff1660808160ff1681525050506100b1565b600080fd5b600060ff82169050919050565b6100618161004b565b811461006c57600080fd5b50565b60008151905061007e81610058565b92915050565b60006020828403121561009a57610099610046565b5b60006100a88482850161006f565b91505092915050565b60805160d46100c960003960006049015260d46000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630dbe671f14602d575b600080fd5b60336047565b604051603e91906085565b60405180910390f35b7f000000000000000000000000000000000000000000000000000000000000000081565b600060ff82169050919050565b607f81606b565b82525050565b6000602082019050609860008301846078565b9291505056fea264697066735822122098754bb675232c7bb479a63e1e60d2857a912be8013333595483a34c39b6f55664736f6c63430008120033

Creation Bytecode

60a060405234801561001057600080fd5b5060405161019d38038061019d83398181016040528101906100329190610084565b8060ff1660808160ff1681525050506100b1565b600080fd5b600060ff82169050919050565b6100618161004b565b811461006c57600080fd5b50565b60008151905061007e81610058565b92915050565b60006020828403121561009a57610099610046565b5b60006100a88482850161006f565b91505092915050565b60805160d46100c960003960006049015260d46000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630dbe671f14602d575b600080fd5b60336047565b604051603e91906085565b60405180910390f35b7f000000000000000000000000000000000000000000000000000000000000000081565b600060ff82169050919050565b607f81606b565b82525050565b6000602082019050609860008301846078565b9291505056fea264697066735822122098754bb675232c7bb479a63e1e60d2857a912be8013333595483a34c39b6f55664736f6c634300081200330000000000000000000000000000000000000000000000000000000000000004

The 0000000000000000000000000000000000000000000000000000000000000004 appended at the end, represents a 32 bytes of data with the value 4.

CREATE2 and CREATE3

CREATE2 uses the creation bytecode also known as init code

CREATE3 does not include the contract initCode