What are Solidity events?
Answer
Events in Solidity are logging mechanisms that emit data to the Ethereum transaction receipt (stored in bloom filters on nodes, not in contract storage). They are used to: (1) Log state changes — notify external listeners when something important happens; (2) Enable efficient filtering — indexed event parameters enable clients to filter events by value; (3) Cheap logging — storing data via events is ~8x cheaper than storing in contract storage. Defining and emitting: event Transfer(address indexed from, address indexed to, uint256 amount); emit Transfer(msg.sender, to, amount). Indexed parameters (max 3 per event) are stored in bloom filters for efficient querying by topic. Non-indexed data is ABI-encoded in the data field. Frontend listening (ethers.js): contract.on("Transfer", (from, to, amount) => { console.log(from, to, amount.toString()) }). Historical event querying: contract.queryFilter(contract.filters.Transfer(), fromBlock, toBlock). The Graph protocol indexes events for efficient historical queries without running archive nodes.