DEV Community

Cover image for Ethereum-Solidity Quiz Q13: What are the main sections in the bytecode of a compiled Solidity smart contract?
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q13: What are the main sections in the bytecode of a compiled Solidity smart contract?

A compiled Solidity smart contract bytecode consists of the following main sections:

  1. Creation Bytecode (Constructor Code)
  2. Runtime Bytecode (Contract Code)
  3. Metadata (Optional)

1. Creation Bytecode (Constructor Code)

This section runs only once during contract deployment:

  • Initializes state variables with default values
  • Executes the constructor function if exists
  • Copies the runtime bytecode into memory and returns it

The constructor code is temporary and not stored on-chain. Only the runtime bytecode is permanently stored.

2. Runtime Bytecode (Contract Code)

This is the actual contract code that gets stored on the blockchain and executed when someone interacts with the contract. It contains all the logic for: public and external functions, internal functions, state variable access and modification, events and error handling

3. Metadata (Optional)

At the end of the bytecode, there is optional metadata containing: used Solidity compiler version, source code hash, compiler settings.

Metadata helps with contract verification but is not executed.

Important:

Deploying is expensive because constructor code must be sent, but running the contract only uses the runtime bytecode(24kb limit).

The final stored bytecode on-chain is relatively small because the temporary constructor code isn't included. This is why contracts can have complex initialization logic without hitting the 24KB bytecode size limit as easily.

Top comments (0)