NethermindEth / starknet.go

Golang Library for StarkNet/Cairo
MIT License
143 stars 95 forks source link

Create example for get events from starknet #578

Open thiagodeev opened 2 weeks ago

thiagodeev commented 2 weeks ago

There isn't any example about how to get a contract event from the starknet. It'll be good to include one in the 'examples' folder

alex-sumner commented 4 days ago

It would be great to have this as it's not that obvious to a newcomer. Here's my experience of it so far...

I can see the Events function on Provider and an example of calling it in events_test.go. I can also see that it takes an EventsInput that holds an EventFilter.

I'm struggling slightly with the Keys value to set on the EventFilter. It's a [][]*felt.Felt but what are the values in it? Presumably they identify which event types and which values of which keys I am interested in? But how is this info held in the array of arrays, and where do the identifying felt values for event type and key come from?

thiagodeev commented 4 days ago

Hi Alex. Thanks, it will be very helpful. Take a look at this page in the starknet.js doc: https://www.starknetjs.com/docs/guides/events/#raw-response. The first "keys" value is the hash of the event name. You can get this value with the GetSelectorFromName starknet-go function.

Also, take a look at some emitted events of an ERC20 contract in voyager/starkscan to understand it better. There's also this: https://docs.cairo-lang.org/hello_starknet/events.html