0Pricing
Web3 & DApp Development Fundamentals · Lesson

Listening to Events

Subscribe to logs.

What Are Events

Smart contracts emit events to log that something happened — a transfer, an approval, a vote. Events are written to the transaction's logs.

  • They are cheaper than storage.
  • Off-chain apps subscribe to them to stay in sync.

Events in the ABI

To decode events, ethers needs their definitions in the ABI:

const abi = [ "event Transfer(address indexed from, address indexed to, uint256 value)", ]; const contract = new ethers.Contract(address, abi, provider);

The indexed keyword marks fields you can filter on.

const abi = [
  "event Transfer(address indexed from, address indexed to, uint256 value)",
];
const contract = new ethers.Contract(address, abi, provider);

All lessons in this course

  1. Connecting to a Provider
  2. Reading Contract Data
  3. Sending Transactions
  4. Listening to Events
← Back to Web3 & DApp Development Fundamentals