Hi guys, Hi @gabba
I have a problem with event listener:
In my .sol file:
function ownerFundUp(uint topUp_val) public onlyOwner payable {
require(msg.value == topUp_val), "msg.value != topUp_val");
if (msg.value != topUp_val)) revert(); // BTW: Is this double check really neacesary?
emit notice("Toped up:",msg.value);
}
On the front end main.js:
async function initEventListeners() { //this function is called only 1 time at beginning
latestBlock = await web3.eth.getBlockNumber();
console.log("LATEST BLOCK NO :",latestBlock);
CONTRACT_INSTANCE.events.notice({fromBlock:latestBlock})
.on('data', event => {
alert("Notice event: "+ event.returnValues[0]+event.returnValues[1].toString())
console.log("Event:",event.returnValues[0],":",event.returnValues[1])
})
}
Strangely , every time, after top-up, I receive 5 TIMES OF THE SAME ALERT at one ?! I have to click OK 5 times to get rid of the alertS.
Did I do something wrong?
It seems It have read ALL events fired since contract started from block ālatestBlockā (but not only the last one) - I gess should filter for the last one only?