How cost is calculated

Higher-level languages such as Solidity compile down to EVM bytecode, translating the contract code into a list of smallest units of computation, called opcodes. These include operations such as ADD (addition operation), SLOAD (load word from storage), and CREATE (create a new account with associated code). The gas cost for each opcode can be found in the yellow paper, and is also listed at https://github.com/bellaj/evm-opcode-gas-costs. The total cost for a given instruction is the sum of the executed corresponding opcodes.

The Ethereum yellow paper defines approximately 130 opcodes. Each of these opcodes has an associated fixed gas price, with some opcodes costing more gas than others. For example, ADD uses three ...

Get Blockchain By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.