I am trying to do a simple test for events. Following is solidity code.
Values received from chgEvent.watch are always correct.
But in chgEvent.get, results1 is empty. chgEvent.get does not get called at emit of event in contract, also there is no error printed.
I am connecting to Ganache.
Please suggest why chgEvent.get is not firing.
pragma solidity ^0.4.0;
contract eventTestContract
{
uint8 public dummy;
event eventOnDummy
(
uint dumm
);
function setDummy(uint8 _dummy)
{
dummy = _dummy;
eventOnDummy(_dummy);
}
function getDummy() returns (uint8)
{
return dummy;
}
}
Following is web3.js relevant code:
var myInstrContract = InstrContractABI.at('0x12e47158657b7ed4ce241ab29cca76b88aa51aab');
var chgEvent = myInstrContract.eventOnDummy({},{fromBlock: 0, toBlock: 'latest' });
chgEvent.get(function (error, results1) {
if (!error) {
console.log("value from event.get "+JSON.stringify(results1.args));
} else {
console.log(error);
}
});
chgEvent.watch(function (error, results) {
if (!error) {
console.log("value from event.watch "+results.args.dumm);
} else {
console.log(error);
}
});