My code:

 instance.MyEvent({}, {fromBlock: 0, toBlock: 'latest'}).watch(function(error, event) {
 if (!error) {

 } else {
}).get(function(error, events) {
 if (!error) {
  } else {

With that, I can retrieve all events with get() in a array, and watch() all of them as well:

All events

The Array (app.js:219) represents get() and each event (app.js:180) has been watched all over again, so there is 269 of them. Once the latest event is the latest watched (obviously), it is retrieved with #events successfully.

But, with so much events, it gets messy. I was wondering if i could filter with some parameter to reduce the number of events returned.

I appreciate the attention!

  • It can be solved if you store your state in a cookie or local storage in the browser. – Ismael Jun 23 '19 at 8:30
  • Thanks for the feedback. I did that (localStorage). The problem with that is: if someone access the dapp from other machine, won't retrieve any transactionHash at first, and then will only retrieve transactionHashs generated while his/her dapp is open. – Guilherme Carvalho Jun 23 '19 at 15:18
  • Actually, I found a way to retrieve the last transactionHash uniting .watch() and get(). I will update the question. I still curious about filtering the parameters, anyway. – Guilherme Carvalho Jun 23 '19 at 15:25
  • Geth and Parity follow web3 api specs and have a limited functionality to filter events, if it is within a block range and filter by indexed paramaters. As alternative you can store in your contract the last block a user generated an event. When your dapp starts query the user last block, and with that can adjust the events block range. – Ismael Jun 24 '19 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.