Skip to main content

How Is the Actual ‘Gas Used’ Calculated for a Smart Contract Execution?

The 'Gas Used' is calculated by summing the pre-defined gas cost for every operation (opcode) executed by the Ethereum Virtual Machine (EVM) during the transaction. Different opcodes, such as storage writes, reads, or simple arithmetic, have different fixed gas costs.

The total sum reflects the computational effort required.

What Is the Difference between an Ethereum Virtual Machine (EVM) and a Smart Contract?
What Are “Opcodes” in the Context of the EVM?
Why Is a Two-Step Approve and Transferfrom Process Often Cheaper in the Long Run for Frequent Interactions?
What Is “Gas” in the EVM’s Execution Model?