Skip to main content

Try it Live

Run GasUsed examples in the interactive playground

GasUsed

GasUsed represents the actual amount of gas consumed by a transaction during execution. Found in transaction receipts as receipt.gasUsed.

Type Definition

Branded bigint representing gas consumed (always non-negative).

Gas Mechanics

Yellow Paper

Gas mechanics defined in Yellow Paper Section 6 (Transaction Execution):
  • Gas vs Gas Price: Total cost = gasUsed × gasPrice (in Wei)
  • Gas Limit: Maximum gas transaction can consume (gasUsed ≤ gasLimit)
  • Refund: Unused gas refunded: (gasLimit - gasUsed) × gasPrice

Gas Ranges

  • Minimum: 21,000 gas (simple ETH transfer)
  • Typical: 50,000 - 200,000 gas (contract interactions)
  • Maximum: Block gas limit (~30M on mainnet)

API

Constructors

from(value)

Create GasUsed from number, bigint, or string.
Throws: InvalidFormatError if value is negative.

Conversions

toNumber(gasUsed)

Convert to number.

toBigInt(gasUsed)

Convert to bigint (identity operation).

toHex(gasUsed)

Convert to hex string.

Comparisons

equals(gas1, gas2)

Check equality.

compare(gas1, gas2)

Compare values (-1, 0, 1).

Utilities

calculateCost(gasUsed, gasPrice)

Calculate transaction cost in Wei.

Common Gas Costs

Basic Operations

Opcodes

See GasCosts for complete list.

Usage Examples

Calculate Transaction Cost

Compare Gas Usage

Analyze Block Gas Usage

Block Gas Limit

Ethereum blocks have a gas limit (~30M on mainnet):
  • Individual transaction: gasUsed ≤ gasLimit (set in tx)
  • Block total: Σ gasUsed ≤ blockGasLimit
  • Full block: High priority transactions fill blocks

EIPs

  • EIP-2929: Gas cost increases for state access opcodes
  • EIP-1559: Fee market change (doesn’t affect gasUsed, but introduces base fee)
  • EIP-3529: Reduction in gas refunds (affects net cost but not gasUsed)

See Also