I want to get network chainId from web3Provider. This is my code.
const isBrowser = typeof window !== "undefined";
const web3provider = isBrowser ? new ethers.providers.Web3Provider(window.ethereum) : null;
const currentChainId = web3provider.network.chainId;
But I get this error. Cannot read properties of undefined (reading 'chainId')
Please tell me how can I access network attribute in web3provider. (Documentation says it's not safe way to access web3provider._network)