0

Hi this is my web3 code

events.watch(function (error,result){
            if (error) {
                console.log('Error:'+JSON.stringify(error));
                res.send({'status':0,'message':error});
            }else{
                console.log('Result:'+JSON.stringify(result));
                res.send({'status':1,'message':result});

            }
        });

Here when ever an event occurs it trigger the watch function. But the problem is, it callback the function, twice. How can I prevent this? In every discussion they just said I fixed and closed the thread. What is the solution to stop triggering twice? I'm using web3 0.20.0. Thank you.

1
  • You're likely processing more than one event. Have you checked to see that the events are what you're expecting? Can you scope the watch to only the event(s) you're interested in?
    – Madbreaks
    Jun 8, 2022 at 17:25

1 Answer 1

0

You could create a hash list based on the transaction's hash and make sure it was not processed before running the code

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.