Forum

How to use web3 to confirm that that an xDai account is selected in Metamask

web3 has the following methods to determine the type of account that is selected in Metamask:

  1. web3.eth.net.getNetworkType(): for xDai, returns “private”

  2. web3.eth.net.getId(): for xDai, returns “100”

Is xDai the only network that has a Network ID of 100?

If other networks also have a Network ID of 100, how can I use web3 to confirm that an xDai account is selected in Metamask?

You can see IDs of the public chains here: https://chainid.network/.

Along with above answer, note that the actual Network Identification consists of the Chain Name (short name) plus the Network ID. The combination of these two makes them unique:

POA Core POA:99
xDaiChain xDAI:100
Ethereum: ETH:1

Hope this helps!