I'm having partial success with a Node.js script I wrote that interacts with one of my Ethereum
Smart Contracts
Here's what's working:
The problem I'm having has to do with capturing EVENTS that are emitted by the contract.
My code won't run cause I keep the following error:
TypeError: theContract.saleTXReceivedEvent is not a function
What's weird is the code I'm using in my Node.js file is the exact same code I've been using in my regular client-side JS files (which are embedded into my HTML files) - which work perfectly well.
Here's the code:
var capturedEvent = theContract.saleTXReceivedEvent();
capturedEvent.watch(function(error, result) {
if(!error) {
console.log("Sale was successful!");
console.log("Results are as follows: ", result);
}
else {
console.log("ERROR!!!! Details: ", error);
}
});
So again, this code works perfectly in my client-side web files, but it gives me an error when in my node.js file:
TypeError: theContract.saleTXReceivedEvent is not a function
It is of course true that saleTXReceivedEvent
is not a Function - its an EVENT, but in terms of the syntax, how else am I supposed to reference it? Why is it working fine in my regular JS files but failing in my NodeJS files?
What's going on here?
I think you forgot events
- try this
var capturedEvent = theContract.events.saleTXReceivedEvent();
...