If you write window.ethereum
into the browser console it will print a proxy object that looks like this:
window.ethereum: Proxy { <target>: {…}, <handler>: {…} }
<target>:
...
isMetaMask: true
networkVersion: "1662582417739"
...
<handler>: Object { deleteProperty: deleteProperty() }
As you see, there is a networkVersion
property which is the equivalent of the web3.eth.net.getId()
line of code (of course when you are using web3.js)
But when you are using ethers.js, I do not see any method that provides networkVersion
. Sure you can get networkId
but not networkVersion
.
Is there any method to get networkVersion
using ethers itself? Or we should fallback to using window.ethereum.networkId
?
Im actually surprised that there is no documentation on this. This networkVersion
is the only way you can get the contract address from its json file (Contract.networks[networkVersion].address). Is this on purpose? A design decision made by the ethers team?