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
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.
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
| Operation | Gas Cost |
|---|---|
| Simple transfer | 21,000 |
| ERC20 transfer | ~65,000 |
| Uniswap V2 swap | ~150,000 |
| Contract creation | 32,000+ |
Opcodes
| Opcode | Gas Cost |
|---|---|
| SLOAD (cold) | 2,100 |
| SSTORE (set) | 20,000 |
| SSTORE (reset) | 5,000 |
| CALL | 100+ |
| CREATE | 32,000+ |
| LOG0 | 375 |
| KECCAK256 | 30 + 6/word |
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
- GasEstimate - Estimate gas before execution
- GasRefund - Gas refunds after execution
- GasCosts - Gas cost constants
- Yellow Paper Section 6 - Transaction execution

