β Master Event Logs & Real-Time dApps
Emit events, use indexed parameters, and listen for blockchain updates
Your Progress
0 / 5 completedβ
Previous Section
Event Listening
π Module Complete: Key Takeaways
π Congratulations!
You've mastered blockchain event logs! You now understand how to emit, filter, and listen to eventsβessential skills for building reactive dApps.
π What You've Learned
π
Event Fundamentals
- β’Logs stored in transaction receipts, not contract storage
- β’50x cheaper than storage (375 gas vs 20,000)
- β’Accessible off-chain only, not by other contracts
π
Event Structure
- β’Topic 0: Event signature (keccak256 hash)
- β’Topics 1-3: Up to 3 indexed parameters
- β’Data field: Unlimited non-indexed parameters
π·οΈ
Indexed Parameters
- β’Enable efficient filtering via Bloom filters
- β’Max 3 indexed params per event
- β’Use for addresses, IDs, and filter criteria
π
Event Listening
- β’WebSocket listeners for real-time updates
- β’Polling with getLogs for batch processing
- β’The Graph for complex historical queries
β‘
Best Practices
- β’Index searchable params (addresses, IDs)
- β’Always remove listeners on cleanup
- β’Handle WebSocket reconnections gracefully
π―
Use Cases
- β’Real-time dApp UI updates
- β’Transaction notifications
- β’Analytics and monitoring dashboards
π― Interactive: Event Logs Knowledge Quiz
Test your understanding with 5 questions about blockchain events and logging.
π οΈ Quick Reference Guide
Event Declaration
event Transfer(
address indexed from,
address indexed to,
uint256 amount
);Event Emission
emit Transfer(
msg.sender,
recipient,
amount
);Event Listening (ethers.js)
contract.on("Transfer",
(from, to, amount) => {
console.log(from, to);
}
);Event Filtering
const filter = contract
.filters.Transfer(
null,
myAddress
);π‘ Real-World Applications
πΌ
DeFi Protocols
Track swaps, liquidity adds/removes, yield farming rewards in real-time.
π¨
NFT Marketplaces
Monitor mints, transfers, sales, and listings with instant UI updates.
π³οΈ
DAO Governance
Log votes, proposals, executions for transparency and auditability.
π
Wallet Applications
Notify users of incoming transactions, approvals, and balance changes.
π Next Steps
1οΈβ£
Build a dApp with events: Create a simple token contract and build a React frontend that listens for Transfer events in real-time.
2οΈβ£
Explore The Graph: Deploy a subgraph to index your contract events and query historical data with GraphQL.
3οΈβ£
Study production contracts: Examine how Uniswap, Aave, and other protocols use events for monitoring and analytics.
4οΈβ£
Implement error handling: Build robust event listeners with reconnection logic and proper error handling.
π
Event Logs Mastered!
You now have the knowledge to emit efficient events, filter them strategically, and build reactive dApps that respond to blockchain activity in real-time.
"Events are the nervous system of the blockchain, carrying signals from smart contracts to the outside world."