I used some services for listening to an event from my smart contract on Ethereum. But I can't find any documents similar to that when working with Flow Blockchain. How can I do that?
How can I listen to an event from my smart contract on Flow blockchain?
485 views Asked by ponfepilot ponfepilot AtThere are 3 answers
On
There are multiple ways of doing this. The easiest I think is to use a service for this. The one we use at .find at the moment is https://graffle.io.
You could also make your own using one of the SDKs. Kitty-items has an example of this https://github.com/onflow/kitty-items/ in javascript.
If you prefer golang I have some event fetching code in overflow https://github.com/bjartek/overflow/blob/main/overflow/event.go. Here is an example on how it can be used: https://github.com/bjartek/overflow/blob/main/overflow/event_integration_test.go#L13
On
Update on above: Graffle no longer provides this capability.
Flow recently released Event Streaming API access which are available from Access Nodes. This offers a push based access paradigm for consuming events without the need for contact polling.
FLIP: https://forum.flow.com/t/flip-73-proposal-to-add-event-streaming-to-access-api/4509
This is a really nice question for a common task! @onflow/fcl package provides you with a helpful method
events, which can be used to "subscribe" to a specific event. You can check events description on Flow Docs Site. Or you can copy/paste code bellow and play around with it:You can also try and play around with working Codesandbox Example