JavaScript

Ethereum DApps: How to Listen for Events

Using the instance we created in step 2, we can subscribe to listen out for any events that it emits.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