Solidity theorytheory 0/50 · 0%
Events · medium

23. Events and indexed topics

How off-chain apps read what happened.

Events write to the transaction log, not storage. Contracts cannot read logs; indexers and front-ends can. Up to three parameters may be `indexed`, which puts them in topics so they can be filtered.

event Staked(address indexed user, uint256 amount);
emit Staked(msg.sender, amount);

Index what you filter on (addresses, ids) and leave amounts unindexed so they stay in the readable data section.

Check your understanding

  1. 1. How many indexed parameters may an event have?

  2. 2. Can a contract read its own past events?

  3. 3. Which parameter is best indexed?