Emit additional keys on Events (e.g. Transfer events of ERC20 / ERC721) #614
Replies: 1 comment
-
|
I agree this is very needed. If we follow closely the Ethereum ERC20 and ERC721 standards when it comes to keys it will be finally possible to discriminate between ERC20 I also agree option 1 is the best technically, but I'm also concerned it will be very confusing for users. It will create a situation where old contracts (that don't use indexed parameters) will have all parameters in
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Cairo's default syntactic sugar for events (i.e.
@eventin Cairo 0 and#[event]in Cairo 1) assigns only a single key to the event which simply put is astarknet_keccakapplied on the decorated variable name. For example, when emitting the following event:The on-chain
keysproperty of the event will only contain:For example, if we analyze the following ERC20 transfer transaction's events,
0x078e56b448ac25e70f96bcda25ef0bcaa5f84637b1a8d51d211274fca086540fwe will see there is a single key in theevents.keysproperty which is the encoded representation of "Transfer":Problem
Emitting the events with only the variable name as a key does not allow us to take full advantage of the
starknet_getEventsRPC API. Namely for "Transfer" we cannot filter ontoorfromdirectly. Current solutions scrape all events of a certain name (e.g. "Transfer") and filter on their local database, beating the purpose of having an event filter to begin with.This is also not aligned with how events (/logs) are treated in L1, where you can properly query on indexed topics. e.g. https://etherscan.io/tx/0x7cf0a012f932e18b179785cc3e9ba1b5354d9f65696a81c0d20825dbf41480cd#eventlog
Solution
Until Cairo's syntactic sugar supports multi-key events, I suggest using the
emit_eventsyscall to emit additional keys that are valuable for indexing.Backward Csompatibility
Moving some of the events field from
datatokeysmight break current solutions that looks for values in theevents.dataproperty. There are 2 options here:Beta Was this translation helpful? Give feedback.
All reactions