Starknet events emission

Hello all,

I have a few questions concerning the current implementation for the Starknet events:

  1. Why is the key associated with an event not similar to the signature used on Ethereum? On Ethereum you use the Keccak256 of the full event signature e.g. Transfer(address, address, uint256), while Starknet only uses the 250 first bits of the Keccak256 of the function’s name e.g. Transfer. What is the reasoning behind this choice?

  2. I was querying events using my node (pathfinder from eqlabs) and I am getting unsorted events within the same block e.g. for a mint contract, if a user mints then transfers the nft in the same block, it happens in some cases that I get the transfer event BEFORE the mint event. Since the rpc doesn’t return the event ID nor the transaction ID I have no way of ordering. This seems to spawn from the definition of the openrpc found here. Does anyone have a possible solution on this?
    EDIT: issue has been created for this ordering problem.

Thanks in advance for your help.

16 Likes

I think this is because cairo use a field with less than 256bit, just 251bit .

12 Likes

To find the key you can have a look here:
https://starknet.io/docs/hello_starknet/events.html
and specifically the end could help you:

from starkware.starknet.compiler.compile import \
    get_selector_from_name

print(hex(get_selector_from_name('increase_balance_called')))

Hope it helps a bit :slight_smile:

12 Likes