I'm using web3 1.0, lets say this is my smartcontract:
contract Foo {
event NewUser(
address userAddress,
uint amount
);
function addUser() public payable{
emit NewUser(msg.sender, msg.value);
}
}
The events get fired in Remix perfectly well.
The problem is when I run a nodejs with express back-end and I try to watch the events with the following piece of code:
contract.events.NewUser({}, function(error, event){
console.log(event);
})
.on('data', function(event){
console.log(event); // same results as the optional callback above
})
.on('changed', function(event){
// remove event from local database
})
.on('error', console.error);
The first log gets called with value null
and when the event can't get triggered. Does anyone have any idea what could be the issue?
var http = require('http');
, is this what you mean? I am using express also. I also have websocket installed.. Could that help in anyway? I don't have a lot of back-end experience