I am using the BoilerPlate and cant seem to figure out how to require a spacific network. For example I would like to use Polygon Testnet. Say a user connects to the website with metamask on Ethereum, how could I request that the user change networks to the Polygon Testnet?
Hi look at this: How to Identify Which Network is Active on MetaMask? » Moralis - The Ultimate Web3 Development Platform
This is for checking what network is active, I can see how this could be used but am using the Moralis ReactJs BoilerPlate which has built in network switching for multiple tokens. Maybe I can use that link to see if the user is on Polygon to then ask them to switch. Is there any way to modify the boilerplates functionality to instead only work with one chain (I’d assume this would be built in)? Everything sign-in related is handled by moralis.
Maybe I can use that link to see if the user is on Polygon to then ask them to switch.
Yep that’s what you can do. Check for the current chainId, and handle everything appropriately e.g. show alert/switch button if the chainId isn’t correct.
The link above should have working methods for that. Otherwise you can use MetaMask’s own event listeners for doing this.
You can basically call this to force user to switch to polygon
if (chainIds?.[chainId] !== chain)
return { isActive: false, text: `Switch to Polygonscan` };
Great idea, I will add this and look for ways to make a button to automatically switch the user over. Any suggestions for this?
Thanks again!
If you add this to your DEX, it will work only when user switch to polygon.