What does the "indexed" keyword do in the below line of code? I'm guessing it just tells the event object that the following input should be logged? Can we use it other places ie outside of events?
event Transfer(address indexed from, address indexed to, uint256 value);
Best Answer
Q What does the "indexed" keyword do in the below line of code? I'm guessing it just tells the event object that the following input should be logged?
The indexed parameters for logged events will allow you to search for these events using the indexed parameters as filters.
Q Can we use it other places ie outside of events?
The indexed keyword is only relevant to logged events.
From Contracts - Events:
Following is some code to test the indexed keywords using The DAO's
Transfer
event with the following definition:Let's search for all The DAO
Transfer
events between block 2254451 and 2256451:Let's search for all
Transfer
events between the same blocks, but with a_from
parameter of0xd430709a70da06c5c25157a97dba3c3e664590af
:Let's search for all
Transfer
events between the same blocks, but with a_to
parameter of0x0a869d79a7052c7f1b55a8ebabbea3420f0d1e13
:But you cannot search for
Transfer
events using the un-indexed parameter_amount
- in the results returned, the filter on_amount
does not work: