Ok, this is doing my head in, I canāt seem to solve this issue, can someone please help.
I keep getting the following when I try to listen for events in my JS fileā¦
Uncaught TypeError: Cannot read property āeventsā of undefined
I can see that the events are logged in my console when I call the functions and I have tested my dApp thoroughly. I just keep getting the same thing in my console when I load the page, it doesnāt matter which event I try to listen for, they all say the same thing. I am clearly missing somethingā¦
Makes no sense to me as I have tried so many different variations of the code to no avail. Iāve been trying to problem solve this for quite a few hours over the last few nights and do not understand why it is telling my this. The following is the simplest piece of code I have used, I have removed everything I feel is unnecessary in order to reduce the likelihood of mistakes and am calling it for the event that is created when the user places a bet, just to get it to work (as I can see this one logged in my console as part of the contract transactionā¦I am not trying to listen for the callback event at this stage (as I read in a post above that there was issues with Ropsten and the callback event listener or something).
contractInstance.events.BetPlaced({
fromBlock: 0
}, function(error, event){console.log(event);})
.on('data', function(event){
console.log(event);
})
.on('error', function(error, receipt) {
console.log(error);
console.log(receipt);
});
Please advise what it is that I am obviously missing/misunderstandingā¦
Edit: (Oct 4th)
@Taha @dan-i - I am at a stand still with this and would like to move on - Iāve spent time every night trying to understand why this isnāt working - I can see the events having been logged in my console after I send transactions to the contract from my front end using contractInstance.methods.enterFunctionHere()
but trying to listen to events with contractInstance.events.EnterEventHere(......)
is resulting in an error stating events undefined or something. Please advise, I would like to move on but canāt solve this, cheers
Edit: (Oct. 7th)
I have now solved the problem. I will hopefully be sharing my completed project within the next day or so.