Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrowserProvider network change event is not fired #4880

Open
kubarenatioN opened this issue Nov 9, 2024 · 2 comments
Open

BrowserProvider network change event is not fired #4880

kubarenatioN opened this issue Nov 9, 2024 · 2 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@kubarenatioN
Copy link

Ethers Version

6.13.4

Search Terms

network event listening

Describe the Problem

Well, I'm just subscribing to provider network change event (using .on('network')) and nothing is emitting when I change network in my Metamask wallet interface.
When subscribing via window.ethereum.on('chainChanged', () => {}) and switching network, the callback is executed.

I'm using hardhat localhost network and Sepolia test network with deployed contract, but as I see, the issue is in provider itself.

Please, help me to understand the issue and resolve it.

Repo with source code (App.tsx, initWeb3 function) - kubarenatioN/dElection@e1efb2c#diff-e56cb91573ddb6a97ecd071925fe26504bb5a65f921dc64c63e534162950e1ebR53

Code Snippet

// Provider initialization
provider = new ethers.BrowserProvider(window.ethereum as any, 'any');

// Later in code when subscribe to events
// This just ignores network change.
      provider.provider.on('network', (...args) => {
        console.log(123, args);
      });

      // This will work and log in console.
      (window.ethereum as any).on('chainChanged', (...args: any[]) => {
        console.log(222, args);
      })

Contract ABI

No response

Errors

No response

Environment

Browser (Chrome, Safari, etc)

Environment (Other)

Metamask Wallet

@kubarenatioN kubarenatioN added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Nov 9, 2024
@kubarenatioN
Copy link
Author

Moreover, similar issue have already happened to another dev. He asked about it here, but get no response - #2842 (comment)

Also, I found this issue - #1396
There we have some explanation on usage of .on('network', () => {}), but still, my original question is about that it doesn't work as intended, or I'm missing some details...

Waiting for some help. By the way, thanks for your great work!

@alejoloaiza
Copy link

Having this issue too with version 6.13.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants