GasRefund
GasRefund represents gas refunded after transaction execution. Post-London (EIP-3529), refunds are capped at gasUsed / 5.
Type Definition
Gas Refund Mechanics
Pre-London (Before EIP-3529)
Large refunds were possible from:- SSTORE clear: 15,000 gas (clearing storage slot)
- SELFDESTRUCT: 24,000 gas (destroying contract)
Post-London (EIP-3529)
Refunds significantly reduced:- Cap: Maximum refund =
gasUsed / 5(20% of gas used) - SSTORE clear: Still generates 15,000 refund, but capped
- SELFDESTRUCT: No longer gives refund
API
Constructors
from(value)
Create GasRefund from number, bigint, or string.
InvalidFormatError if value is negative.
Conversions
toNumber(refund)
Convert to number.
toBigInt(refund)
Convert to bigint (identity operation).
toHex(refund)
Convert to hex string.
Comparisons
equals(ref1, ref2)
Check equality.
Utilities
cappedRefund(refund, gasUsed)
Apply EIP-3529 refund cap.
min(refund, gasUsed / 5)
Usage Examples
Calculate Effective Gas Cost
Compare Pre/Post London
Multiple Storage Clears
Refund Sources
SSTORE Operations
| Operation | Gas Cost | Refund (Pre-London) | Refund (Post-London) |
|---|---|---|---|
| Zero → Non-zero | 20,000 | 0 | 0 |
| Non-zero → Non-zero | 5,000 | 0 | 0 |
| Non-zero → Zero | 5,000 | 15,000 | Capped at gasUsed/5 |
| Non-zero → Same | 100 (warm) | 0 | 0 |
SELFDESTRUCT
| Era | Gas Cost | Refund |
|---|---|---|
| Pre-London | 5,000 | 24,000 |
| Post-London | 5,000 | 0 |
EIP-3529 Rationale
Problems with Old Refund System
-
Gas Tokens: Exploited refunds for profit
- Store data when gas cheap
- Clear data when gas expensive
- Get refund at high gas price
- Block Variability: Large refunds caused unpredictable block gas usage
- Complexity: Made gas economics hard to reason about
Post-3529 Benefits
- No Gas Tokens: Capped refunds eliminate exploit
- Predictable Costs: Users pay closer to actual gas used
- Simpler Economics: Easier to estimate transaction costs
- Faster State Growth: Reduced incentive to keep unnecessary storage
Refund Cap Formula
totalRefund: Sum of all refunds from SSTORE operationsgasUsed: Actual gas consumed by transaction- Division rounds down (integer division)
Usage Patterns
Check if Refund is Capped
Calculate Maximum Possible Refund
London Hard Fork
Date: August 5, 2021 (Block 12,965,000) Changes:- EIP-3529: Refund reduction
- EIP-1559: Fee market change
- EIP-3198: BASEFEE opcode
- EIP-3541: Reject new contracts starting with 0xEF
See Also
- GasUsed - Actual gas consumed
- GasEstimate - Estimate gas before execution
- EIP-3529 - Reduction in refunds
- EIP-2929 - Gas cost increases
- Yellow Paper Section 6 - Execution model

