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.

Subscribe.on fires past events

See original GitHub issue

Ethers Version

5.6.5

Search Terms

subscribe new events filter

Describe the Problem

Hi,

when I am subscribing to a contract’s events I am also seeing past events even the filter fromBlock: 'latest' is set.

Am I doing something incorrectly?

   import { useProvider } from "wagmi";

    const provider = useProvider();

    const contract = await new ethers.Contract(
    address,
    abi,
    provider
  );

    const listener: Listener = (id: BigNumber, user: string) =>
    console.dir("id", id.toString(), "user", user)

    contract.on(
    // "CancelOrderEvent",
    {
      topics: [utils.id("CancelOrderEvent(uint256,address)")],
      fromBlock: "latest",
    },
    listener
  )

I should mention, I am using wagmi however, I don’t think that changes the way ethers works as I just work with the ethers.Contract.

Help appreciated, cheers 🙏🏼

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), node.js (v12 or newer), Hardhat, Ganache

Environment (Other)

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Jul 27, 2022

Thanks! I have found the bug.

Yes, this was introduced with the fix for networks which have non-consistent event indexing (e.g. Polygon and BSC).

This fix will go out in v5.7.0.

2reactions
kvansteecommented, Jun 24, 2022

I’m getting previous events fired with contract.on using ganache testnet. Can I assume this is an artifact of ganache?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ready For Wildfire App
Use the CAL FIRE app to create a personalized wildfire readiness plan and learn about active incident information to find "fires near me."...
Read more >
Subscribe fires twice when I revisit a page - angular
As your old subscriptions will keep listening to old Subjects. ... This worked perfectly and prevents triggering multiple subscribe events.
Read more >
web3.eth.subscribe — web3.js 1.0.0 documentation
The web3.eth.subscribe function lets you subscribe to specific events in the ... "error" returns Object : Fires when an error in the subscription...
Read more >
Stats & Events - CAL FIRE - CA.gov
Stats and Events. ... Subscribe To Receive News Releases and Incident Updates: Click to subscribe for news ... Historical Wildfire Activity Statistics ...
Read more >
Subscribe to Platform Events Unit | Salesforce Trailhead
Now that you've seen how to publish platform events, how do you subscribe to them to be ... Publishing the event causes the...
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