←
Previous Module
Reentrancy Attack Simulator

πŸ“‹ Event Logs: How Contracts Talk to the World

Learn how smart contracts emit events to communicate with dApps

πŸ“‹ 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 Common

Track token/ETH transfers between addresses

Gas Cost
~375 gas per topic
Example
ERC-20, ERC-721 transfers
Use Case
Wallet updates, transaction history

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:

1
Cheap Storage
~375 gas per indexed topic vs. 20,000 gas for storage slot
2
Not Accessible On-Chain
Other contracts cannot read eventsβ€”only off-chain applications can
3
Searchable & Filterable
Indexed parameters enable efficient filtering by address, value, or topic
4
Permanent Record
Events are part of blockchain history and cannot be deleted

Why Events Matter

πŸ’»
dApp Integration

Frontend applications listen to events to update UI in real-time without polling contract state.

πŸ“Š
Analytics & Monitoring

Index events to build analytics dashboards, track metrics, and monitor contract activity.

πŸ”
Audit Trails

Permanent record of contract actions for compliance, debugging, and historical analysis.

πŸ’°
Cost Efficiency

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)