Indexed (keyword)

In Solidity, the indexed keyword in an event definition is used to indicate that the value of a particular parameter should be stored in a way that makes it easier to search for. When an event is emitted, the values of its indexed parameters are stored in a separate data structure called an "event index" that can be used to efficiently filter and search through large numbers of events.

Indexed parameters are specified in the inputs array of the event definition and are identified by setting the indexed field to true. Here's an example:

event Transfer(address indexed _from, address indexed _to, uint256 _value);

In this example, the first two parameters are indexed, which means that they will be stored in the event index. The third parameter is not indexed and will only be stored in the event log.

When searching for events, you can use the indexed parameters to filter the results. For example, if you want to find all events where a particular address was involved in a transfer, you can specify that address as one of the indexed parameters in the event definition, and then use that value to filter the results when querying the event index.

Last updated