Is there any difference between the two?
event NewEvent(address addr)
event NewEvent(address indexed addr)
Indexed parameters are slightly more expensive than unindexed parameters.
The general formula for event gas cost is:
375 + 375 * numberOfIndexedParameters + numberOfUnindexedBits
So in your example, the cost would be:
event NewEvent(address addr) // 375 + 375 * 0 + 160 = 535
event NewEvent(address indexed addr) // 375 + 375 * 1 + 0 = 750
Given an event name and series of event parameters, we split them into two sub-series: those which are indexed and those which are not. Those which are indexed, which may number up to 3, are used alongside the Keccak hash of the event signature to form the topics of the log entry. Those which are not indexed form the byte array of the event.
Indexed events can be sought for efficiently using an event filter. When you want to be able to look up whether something has happened in the past, you should use an indexed event parameter.
An example:
Let's assume you want to proof that sometime in the past, you transfered some ERC-20 token to your friend. In that case, you'll want to find all Transfer
event that token emitted in the passed with your address as a sender, and the address of your friend as a recipient. This lookup can be done easily if the sender and recipient addresses of the event were indexed.
Now, there is a catch.
Indexed arguments will not be stored themselves. You can only search for the values, but it is impossible to retrieve the values themselves.
Only use indexed
for event parameters you want to be able to search for!