What are events in Solidity, and how do you use them in a real project?
What the interviewer wants to hear
- Events write logs to the transaction receipt, cheaper than storage
- Contracts cannot read logs; they are for off-chain consumers
- Up to three indexed parameters can be filtered efficiently
- Frontends and indexers like The Graph use them for history and updates
- Emit an event for every important state change
Model answer
An event is a way for a contract to write a log entry into the transaction receipt, for example Transfer(from, to, amount). Logs are much cheaper than storage, but contracts cannot read them, so they are meant for off-chain tools. Up to three parameters can be marked indexed, which puts them in topics so nodes can filter by them, such as all transfers to one address. In a real project I emit an event for every important state change, like deposits, withdrawals, role changes and parameter updates. The frontend listens to them for live updates, and an indexer such as a subgraph or a custom service stores them in a database for history and analytics. Good events are also important for monitoring and incident response, because alerts usually watch for unusual events.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Blockchain Developer questions
- Explain what a blockchain is to someone who is not technical.
- What is a smart contract, and what are its main limitations?
- What is the ERC-20 standard and what are its key functions and events?
- What is the difference between proof of work and proof of stake?
- Describe the basic architecture of a decentralised application (dApp).
- How does a crypto wallet work, and what is the role of the private key and the seed phrase?
- How are transaction fees calculated on Ethereum today?
- Compare ERC-20, ERC-721 and ERC-1155. When would you use each?
- What are Layer 2 networks, and why are they important for Ethereum?