Events are Solidity's way to write structured log entries to the blockchain when something happens in a contract. You declare an event with the event keyword and fire it with emit, and the data is stored in the transaction receipt's logs rather than in contract storage. Because logs are far cheaper than storage and can be searched by off-chain applications, solidity events are the standard way to tell wallets, front ends and indexers what a contract did.
This guide uses Solidity 0.8.x and ethers.js v6 for the off-chain examples, and assumes you know functions, mappings and msg.sender.
An event declaration lists typed parameters. Calling emit EventName(args) writes a log entry with those values.
The event is part of the contract's ABI, so tools that read the ABI know how to decode it. Contracts cannot read logs after they are written; logs are for the outside world.
Each log entry holds the address of the contract that emitted it, a list of up to four topics, and a data field.
Transfer(address,address,uint256). This identifies the event type.indexed parameters.Anonymous events (declared with anonymous) skip topic 0 and may use four indexed parameters, but they are rare and harder to filter, so most contracts do not use them.
Marking a parameter indexed puts it in a topic, which lets nodes filter logs quickly. You can mark up to three parameters of a normal event as indexed.
| Property | Indexed parameter | Non-indexed parameter |
|---|---|---|
| Stored in | Topic | Data field |
| Searchable by value | Yes | No |
| Decoded value for dynamic types | Hash only | Full value |
| Gas cost | Slightly higher | Lower |
For dynamic types such as string and bytes, an indexed parameter stores only the hash of the value, so you cannot recover the original text from the topic. If you need to read the text, leave it non-indexed or emit it twice.
Here, an app can search for all registrations by one user and still read the full name from the data.
Applications use the logs in two ways: they read past events with a filter, and they subscribe to new ones. This example uses ethers.js v6.
The from filter works because that parameter is indexed. A block range limit is common on public RPC providers, so query in chunks for long histories.
Writing a value to storage costs far more gas than emitting an event, because the chain must keep storage for every node. A log costs a base amount plus a charge per topic and per byte of data. The trade-off is that contracts cannot read events.
Deposited or OwnershipTransferred.Transfer and Approval events so wallets and explorers can read your token.Custom errors and events are separate: errors undo a call, while events record that a call succeeded. If the transaction reverts, its events are discarded too.
No. Logs are not accessible from contract code. Only off-chain clients and indexers read them.
Up to three in a normal event, and up to four in an anonymous event.
Yes, but much less than storage. The cost grows with the number of topics and the bytes of data.
Full nodes keep logs as part of block history, but they are not part of the state, so a node that prunes history may drop old ones. Use an indexer for long-term queries.
Declare events with event, fire them with emit, and use indexed on up to three parameters you want to filter by. Logs are cheap, public and unreadable by contracts, so use them for history and notifications while storage keeps the state. Off-chain code decodes and filters events through the ABI, using libraries such as ethers.js.