π Event Logs: How Contracts Talk to the World
Learn how smart contracts emit events to communicate with dApps
Your Progress
0 / 5 completedπ Understanding Event Logs
Events are the eyes and ears of blockchain applications. They allow smart contracts to communicate with the outside world, enabling real-time monitoring, historical analysis, and seamless dApp integration.
π― Interactive: Event Type Explorer
Explore the 4 main types of blockchain events:
Transfer Events
Most CommonTrack token/ETH transfers between addresses
What Are Event Logs?
Event logs are records emitted by smart contracts during execution. They're stored in the blockchain's transaction receipts (not in contract storage) and are accessible to external applications but not to other smart contracts.
Key Characteristics:
Why Events Matter
Frontend applications listen to events to update UI in real-time without polling contract state.
Index events to build analytics dashboards, track metrics, and monitor contract activity.
Permanent record of contract actions for compliance, debugging, and historical analysis.
50x cheaper than contract storageβperfect for historical data that doesn't need on-chain access.
Real-World Example
ERC-20 Transfer Event
event Transfer(
address indexed from,
address indexed to,
uint256 value
);
// Emitted when tokens are transferred
function transfer(address to, uint256 amount) public {
balances[msg.sender] -= amount;
balances[to] += amount;
emit Transfer(msg.sender, to, amount);
}π‘ What Happens:
- β’ indexed parameters (
from,to) are searchable - β’ Wallets listen for events where
to == userAddress - β’ UI updates balance without querying contract
- β’ Event stored in transaction receipt forever
Events vs. Storage
πEvents (Logs)
- β~375 gas per indexed topic
- βAccessible off-chain only
- βEfficient filtering by topics
- βPerfect for historical data
- βCannot read from contracts
πΎContract Storage
- βAccessible on-chain
- βContracts can read it
- β~20,000 gas per slot (50x more)
- βNo built-in filtering
- βExpensive for historical logs
π‘ Key Insight
Events are the bridge between blockchain and traditional applications. They enable:
- β’Real-time notifications (wallet received tokens)
- β’Historical queries (all transfers from address X)
- β’Analytics dashboards (trading volume, active users)
- β’Cost-effective logging (50x cheaper than storage)