Get chainId from user

Im using vanilla js (no react components), and just metamask (no walletconnect). How do I get the chainId of the network the user is currently logged in to? I have another web3 connection to a speedynode pulling some mainnet info, but while Iā€™m developing, Iā€™d like to do things like make sure the user is on the Polygon Mainnet before they interact with any contracts

await Moralis.enableWeb3()
chainId = await Moralis.getChainId()
1 Like