question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FCL getEvents not printing events in recent block height

See original GitHub issue

Problem

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) image

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. image

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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vishalchangranicommented, Jan 29, 2021

I have addressed this issue in this PR https://github.com/onflow/flow-go/pull/331

1reaction
orodiocommented, Jan 29, 2021

@vishalchangrani @psiemens

Created an issue (#492) to expose the ability for fcl.latestBlock to use the latest sealed block

@FishFr0g in the mean time I think you can replace fcl.latesetBlock() in your code with the following:


function latestBlock() {
  return fcl.send([
    fcl.getLatestBlock(true)
  ]).then(fcl.decode)
}

async function poll() {
  let key = "A.c1e4f4f4c4257510.Market.MomentPurchased";
  let hwm = (await latestBlock()).height - 1;

  while (1) {
    await new Promise((r) => setTimeout(r, 1_000));
    var end = (await 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);
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow Client Library (FCL) API Reference - Flow Developers
A builder function that returns all instances of a particular event (by name) within a height range. ⚠️The block range provided must be...
Read more >
Flow JS SDK Error: Response closed without headers
Hi there - you can point your FCL to HTTP Proxy by replacing the endpoints in ... FCL getEvents not printing events in...
Read more >
Network (fabric-gateway 1.1.2-SNAPSHOT API) - Hyperledger
Get events emitted by transaction functions of a specific chaincode from the next committed block. The Java gRPC implementation may not begin reading...
Read more >
Untitled
Moore collection denver, Witold sobieraj poznachowice, How not to live your life ... Get-events, J.s bach cello suite no.1, Bag raiders sunlight download, ......
Read more >
Untitled
Anafen szaim, Font book preview not working, The last of us walkthrough ... 1974 us historical events, Small basement bar pictures, Covinoc inmuebles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found