1

I want to update UI elements of an app based on contract events. My problem is, that I do not receive any events that happen after the site has been loaded (seems like the subscription does not work). Here is my code (contracts are already deployed and connected via Web3):

myContract.events.MyEvent({}, function(){console.log("event triggered")});

When I specify start and end blocks like in the following, it am getting all previous event, but still do not receive any further ones that have been emitted after the page has been loaded:

myContract.events.MyEvent({fromBlock:0, toBlock: 'latest'}, function(){console.log("event triggered")});

So it seems, that the code is not permanently listening for the event. Any suggestion on how to solve this? I am using Web3 1.3.1 and MetaMask 9.0.0

1
  • It seems like this is only a problem with the local Ganache network. When I try to listen to events on an actual test network like Rinkeby above code is working. Jan 17, 2021 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.