You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
// 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
The text was updated successfully, but these errors were encountered:
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!
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-e56cb91573ddb6a97ecd071925fe26504bb5a65f921dc64c63e534162950e1ebR53Code Snippet
Contract ABI
No response
Errors
No response
Environment
Browser (Chrome, Safari, etc)
Environment (Other)
Metamask Wallet
The text was updated successfully, but these errors were encountered: