Smart contracts are not just static code—they emit events that can be listened to in real-time, enabling dApps to react immediately to on-chain activity. In a modern backend built with NestJS, listening to Ethereum events using Web3.js is a powerful way to automate workflows, trigger actions, or update state based on blockchain transactions.
In this guide, we’ll walk you through how to:
- Connect to the Ethereum blockchain with Web3.js
- Subscribe to smart contract events
- Cleanly handle connections and disconnections
- Integrate the event listener into a NestJS service lifecycle