0PricingLogin
Web3 & DApp Development Fundamentals · Lesson

Listening for Events

Off-chain subscriptions.

Consuming Events Off-Chain

Events are useless until something listens for them. Off-chain apps - web front-ends, bots, and indexers - subscribe to logs to react to on-chain activity.

Libraries like ethers.js and web3.js make this straightforward.

Listening with ethers.js

With ethers.js you attach a listener using contract.on(eventName, callback). The callback receives the decoded parameters plus the raw event object.

<code>contract.on('Transfer', (from, to, amount, event) => {
    console.log(from, '->', to, amount.toString());
});</code>

All lessons in this course

  1. Declaring Events
  2. Indexed Parameters
  3. Listening for Events
  4. Events vs Storage
← Back to Web3 & DApp Development Fundamentals