I'm learning to develop Oracles, and, like all of us, I've encountered a dated article. After fixing all the Solidity changes (version, adding emit to fire an event, changing constructor function to constructor etc.), I've encountered a JS issue.

I'm supposed to be listening to an event, and when it gets fired, fetch some data, and call a contract function to store said data.

I'm using @truffle/contract to access my contract data in JS.

There's a line saying something like myContract.myEvent().watch(.... I keep getting .watch is not a function. I'm assuming at one point, watch has been replaced. I can't find when and by what.

I did find some Truffle documentation saying that you can treat the event like an EventEmitter (i.e. hang .on statements on it), but hat does not have the loop effect watch had (i.e. the script keeps running and waiting for the event, instead of just running once and exiting.

TL;DR: what replaced watch? Should I write an infinite loop around an EventEmitter code?

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.