1

I have a dapp running on rinkeby at the moment, you can try it now on cryptogol.io, but I am facing a problem when reading events from the Blockchain. For example, yesterday I make the events happens, so everyone can interact with the site. Here is the code for listening to the event (it is being ran every time someone opens the page at www.cryptogol.io/market.html:

listenForEvents: function() {
  console.log("escuchando")
    App.contracts.KickerADN.deployed().then(function(instance) {
        instance.AdnCreated({}, {
            fromBlock: 0,
            toBlock: 'latest'
        }).watch(function(error, event) {
            App.loadBody(event.args._adn.toNumber());
        });
    });
}

When you open the page it can take more than 1 minute to load the event. The function is being called normally but the event is not getting it on time. Any idea?

  • You are retrieving all events from block 0, this is a demanding task. You can try to load on demand, start from the latest and go backward. And keep a cache of previously loaded events, so you do not have to reload everything from the blockchain. – Ismael Feb 26 at 19:32
1

The event of the tnx call only fired when the tnx was confirmed a.k.a when tnx was including in a sealed block so it takes time.

  • Thank you... But the tnx was confirmed yesterday, I know it can takes time, but more than a minute to load something that already was confirmed is not very good, is it? – Gustavo Alvarez Aug 29 '18 at 13:32
  • No, each time you call the function it will create a new tnx; not the old one – Ha ĐANG Aug 29 '18 at 13:36
  • that's for funstions that writes on the blockchain, but I am just trying to read from the blockchain... – Gustavo Alvarez Aug 29 '18 at 19:14
  • Then you can get tnx's receipts/logs to extract the events from it – Ha ĐANG Aug 30 '18 at 2:33
0

How about change design? It is loading all blocks. AdnCreated is event accessor and the 1st arg is search condition for indexed event. It will reduce scanning target count. 2nd arg is skipper. fromBlock allows you to skip some block. And so if you design your contract to ignorable obsoleted state, checkpointing would make your log feching faster. And putting cache server is also one choice. Some of users would say it's centralized entity though, actually that server isn't killing fund safety.

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.