Zephyrnet Logo

Ethereum DApps: How to Listen for Events

Date:

Figure 4: Subscribe to ‘MyEvent’

As stated earlier, the event we want to listen for is called MyEvent, and figure 4 shows us how. Our myContract instance has an accessor called events from which we can target MyEvent. This is an asynchronous function that returns a promise, and it’s called every time MyEvent is emitted.

Line 3 defines what happens once data has been returned from the promise. Here we’re simply logging the event values to the console, but this is where we’d code features like alerts or interface updates to update the user on the event that’s just occurred.

Using this logic, every MyEvent emitted from MyContract will be caught here.

Source: https://medium.com/better-programming/ethereum-dapps-how-to-listen-for-events-c4fa1a67cf81?source=rss——-8—————–cryptocurrency

spot_img

Latest Intelligence

spot_img

Chat with us

Hi there! How can I help you?