Bytecode

Bytecode (also called portable code or p-code[citation needed]) is a form of instruction set designed for efficient execution by a software interpreter.

Bytecode is the compiled code that can be executed by a virtual machine, such as the Ethereum Virtual Machine (EVM). Bytecode is typically generated by compiling source code written in a high-level programming language, such as Solidity, into machine-readable instructions that can be executed by the EVM.

Example

// Solidity code
pragma solidity ^0.8.0;

contract SimpleContract {
  uint256 public value;

  function setValue(uint256 newValue) public {
    value = newValue;
  }
}

// Bytecode (in hexadecimal)
608060405234801561001057600080fd5b5061019b806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780638e7b8d7814605c575b600080fd5b603d606d565b005b604760c2565b6040518082815260200191505060405180910390f35b60008090505b600081359050606081565b9291505056fea265627a7a72315820631d6a7a6a60cf6f6959c1d3f526b3d31db41678a70c8b75da3d7a1362e2eb1964736f6c634300050c0032

In this example, we have a simple Solidity contract called "SimpleContract" that includes a public variable called "value" and a function called "setValue" that can be used to update the value of "value".

The Solidity code is compiled into bytecode, which is a hexadecimal string that represents the machine-readable instructions that can be executed by the EVM. The bytecode is much longer and more complex than the original Solidity code, and includes a set of low-level instructions that can be executed by the EVM to update the state of the blockchain and execute the smart contract.

Last updated