Replies: 1 comment
-
Those events are EIP-1193 specific as you said. An ethers Provider is not related to an EIP-1193 compliant Provider as far as I'm concerned and according to what I've been reading on GitHub. It is just the name that confused me and probably you too. An ethers Provider is a higher-level interface compared to an EIP-1193-compliant Provider. They don't necessarily have those events that are defined in the EIP-1193 standard. The ethers library creates a strong division between the operation a Provider can perform and those of a Signer, which for example Web3.js lumps together. A Provider in ethers is a read-only abstraction to access blockchain data. See the common terminology in ethers' documentation. I would recommend you the following issues and discussions to have a better understanding but again I'm not the owner of the project.
I think what you can do is target the EIP-1193-compliant provider since an ethers provider wraps it. Note that provider?.provider?.on("chainChanged", (chainId) => {
// Handle the new chain
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Currently providers only provide support for a few events:
https://docs.ethers.io/v5/api/providers/provider/
However external provider (e.g. metamask) emit additional events that are useful when creating UIs.
https://docs.metamask.io/guide/ethereum-provider.html#events
For example:
From eip-1193:
"
The Provider MUST implement the following event handling methods:
on
removeListener
"
In our case "The provider" would be the external provider defined.
Currently
ethers.providers.ExternalProvider
class does not support a.on()
method.It would be nice to have one of the following;
a) Expand events used in
ethers.providers.Web3Provider
class.b) Allow events on
ethers.providers.ExternalProvider
.Disclaimer:
I'm somewhat new to ethers and I do have the slight feeling that the above is by design. If yes, I would appreciate any guidance as to how I should be correctly handling these event using ethers.
Follow up:
I found and read the best practices section, where I can see you use the "network" event to detect network change. This is great and servers the same purpose as listening for "chainChanged".
Is there is a complete list of events that an
ethers.providers.Web3Provider
instance can listen for?There is no mention of the network event in the docs.
Overall question
Should we be able to call
provider.on(<events>)
for the following events:accountsChanged
chainChanged
As per EIP-1193.
Best,
Tony
Beta Was this translation helpful? Give feedback.
All reactions