Overview
Opcode:0x31
Introduced: Frontier (EVM genesis)
BALANCE retrieves the balance (in wei) of any account on the blockchain. It pops an address from the stack and pushes the balance of that address.
Specification
Stack Input:- Frontier - Homestead: 20 gas
- Tangerine Whistle (EIP-150): 400 gas
- Istanbul (EIP-1884): 700 gas
- Berlin (EIP-2929): 2600 gas (cold) / 100 gas (warm)
Behavior
BALANCE accesses the blockchain state to retrieve an account’s balance. The address is popped from the stack as a uint256, with only the lower 160 bits used. Key characteristics:- Returns balance in wei (1 ether = 10^18 wei)
- Returns 0 for non-existent accounts
- Gas cost depends on warm/cold access (Berlin+)
- Does not distinguish between EOA and contract accounts
Examples
Basic Balance Check
Contract Balance Check
Payment Validation
Gas Cost
Historical evolution:
Cold vs Warm Access (Berlin+):
- Cold: First access to an address in transaction (2600 gas)
- Warm: Subsequent accesses to same address (100 gas)
Common Usage
Minimum Balance Requirement
Balance Tracking
Withdrawal Pattern
Payment Routing
Security
Balance Checks Are Not Atomic
Self-Destruct Race Condition
Integer Overflow in Balance Calculations
Implementation
- TypeScript
Edge Cases
Zero Address Balance
Non-Existent Account
Maximum Balance
Stack Underflow
References
- Yellow Paper - Section 9.1 (Execution Environment)
- EVM Codes - BALANCE
- EIP-150 - Gas cost changes (Tangerine Whistle)
- EIP-1884 - Repricing (Istanbul)
- EIP-2929 - Access lists (Berlin)
- EIP-2930 - Access list transactions

