-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
chainChanged send a String instead of an integer #899
Comments
The goal of Ethers is not to mimic EIP-1193 or any other Provider. The Web3Provider (which will be renamed in the future) is designed to accept a variety of backends (such as So, ethers v5 will always return a number for chain ID. So, any library which relies on an "ethers Provider", does not need to worry about handling fragmentation amongst backend providers, ethers will de-fragment that for you. Also, keep in mind, if you want to support a backend which can change networks, you need to specify the network What you likely want is something like: // Notice this: ----------------------------------------------------v
const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
const network = await provider.getNetwork()
const chainId = network.chainId
// You can also then use this:
provider.on("network", (network, oldNetwork) => {
console.log(network.chainId);
}); Without the For more information see #866 . Make sense? :) |
(oh! Another note; there will always be at least one |
Many thanks for this clarification.
Where provider is window.ethereum. Does It means that I can rely on a ethers Provider instead to track wallet events ? By the way thanks for your new release. Seemless migration. Thanks |
This is prolly what you are interested in: https://docs.ethers.io/v5/api/providers/provider/#Provider--events There is no Keep in mind a Provider in ethers is meant to be read-only, the Signer-based events are outside the scope of Provider. A wrapper can be used on a JsonRpcProvider (which Web3 extends) to detect account changes. The conflation of what a Signer and Provider are in ethers with what most other libraries refer to singularly as Provider makes some of these events and ideas hard to resolve. In the future, the JsonRpcProvider sub-class may add an event equivalent to |
Thanks for the link. |
Exactly how I recommend doing it. I want my Signer to be as far removed from my main Provider as necessary. :) Closing this now, but feel free to re-open if you have further issues. Thanks! :) |
I'm using ethers 5.X and started to beta test the upcoming Metamask 8.0.0
Lately I focused on https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md and realized the following situation.
Metamask used to send chainId as a decimal in the following snippet but now rather send an hexadecimal string who needs to be parseInt.
MetaMask/metamask-extension#8837
In my code I use the following to retrieve the chainId
const web3 = new window.ethers.providers.Web3Provider(window.ethereum)
const network = await web3.getNetwork()
const chainId = network.chainId
However in ethers chainId is a number rather than an hexadecimal string.
My motivation here is more to avoid any fragmentations between libraries in my dapp and a wish to report what I noticed. Any thought will be greatly appreciated.
Thanks
The text was updated successfully, but these errors were encountered: