FCL getEvents not printing events in recent block height
See original GitHub issueProblem
Trying to get events in real time, won’t print all events but if you look back at the same block height about 30 seconds later, it will print all the events that happened in that block height.
Steps to Reproduce
I used this script
async function poll() {
  let key = "A.c1e4f4f4c4257510.Market.MomentPurchased";
  let hwm = (await fcl.latestBlock()).height - 1;
  while (1) {
    await new Promise((r) => setTimeout(r, 1_000));
    var end = (await fcl.latestBlock()).height;
    if (hwm >= end) {
      console.log("hwm is the same", hwm, end);
      continue;
    }
    var events = await fcl.send([fcl.getEvents(key, hwm, end)]).then(fcl.decode);
    console.log(`Events from ${hwm} to ${end}`, events);
}
Which checks 1 height before the current block to see if any events occurred and a lot of the times it won’t print anything from the block height (Empty array in the logs)

I took that same block height which was about 30 height from start to finish and checked for events around 30 seconds to a minute later, and it printed all of them that occurred.

Not sure if this is a bug, but it seems like even though the block isn’t the current height, it still takes almost a minute for all the events to be loaded into that block height, I’m still pretty new to this technology so if I wasn’t clear enough I can specify more if needed, your help would be appreciated
Issue Analytics
- State:
 - Created 3 years ago
 - Comments:10 (5 by maintainers)
 

Top Related StackOverflow Question
I have addressed this issue in this PR https://github.com/onflow/flow-go/pull/331
@vishalchangrani @psiemens
Created an issue (#492) to expose the ability for
fcl.latestBlockto use the latest sealed block@FishFr0g in the mean time I think you can replace
fcl.latesetBlock()in your code with the following: