1

This web3js event listener is part of a Voting Dapp. The listener listens for a transactions and re-renders the page to show updates.

listenForEvents: function() {
App.contracts.Election.deployed().then(function(instance) {

  instance.votedEvent({}, {
    fromBlock: 0,
    toBlock: 'latest'

  }).watch(function(error, event) {
    console.log("event triggered", event)
    // Reload when a new vote is recorded
    App.render();
  });
});
},

Even after a lot of searches,i cannot find an explanation for the part

{
    fromBlock: 0,
    toBlock: 'latest'
}

I think this part is causing to render the app in loop. Event declaration is like

event votedEvent (uint indexed _candidateId); 

The statement that calls the event is

votedEvent(_candidateId);

Any links or topics to search for will be helpfull.Thanks in advance :-)

1

Removing App.render(); solved for me. Because we render the app while initialising the solidity class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.