Some watched events randomly don't show up
See original GitHub issueI’m using await contract.Method().watch({resourceNode: 'solidityNode'}, (err, res) => {...}); used on a few different methods.
It seems that some of the events do not trigger the function at all and simply go missing, meaning that the Dapp has an incomplete view of the state updates. This is a real nuisance.
I had the same events being listened to on both a Node.js instance and on some webpages using TronLink, and I discovered that the events that go missing are different for each instance (one page showed all the events). This means that the problem is not with the contract invocations or the events themselves but something to do with the code that retrieves the events.
Looking at the code it only seems to check for events every 3 seconds and only gets events for the latest block, so it is possible that it could be completely missing blocks. The getEvents function should check all blocks since the last time it was called, not just the latest block, and even if the interval is set for 20 seconds (simulating some sort of processing delay) it should still pick up all the events for the last few blocks to ensure that none are missed.
It is entirely possible that in a web page processing the UI could delay the getEvents function considerably, so that it gets called every 3 seconds cannot be relied upon. Same in the server, if there are a bunch of events to process from one block that involve heavy processing each, then the next block will be missed, which is not acceptable.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)

Top Related StackOverflow Question
@forhas we all left tron so maybe don’t expected those issue to be fixed
In case it might help anyone, this is the code I’m using instead of using
contract.Method().watchto discover the events due to this problem (seems to work reliably for recent events).(Note that the 60 seconds on the first line is to allow for the fact that the newly loaded events will have timestamps in the past, and when onlyConfirmed is on, this gap will include the time it takes for the transaction to confirm on the solidity node. Even without onlyConfirmed there should still be at least 3 seconds because of waiting for the interval to trigger and this is also the maximum time since the previous block was mined.)
This also has the advantage that it only does one request for all possible events that can be emitted by the contract. If you wanted you could add the eventName parameter to the options for getEventResult so you wouldn’t have to check the name.
Maybe the
contract.Method().watchfunctionality could use logic similar to this to achieve the desired effect.