-
-
Save Austinhs/9ce2c903021320da50a4b80def729526 to your computer and use it in GitHub Desktop.
change network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check for the correct chain | |
| const { chainId } = await provider.getNetwork(); | |
| if (!(chainId === web3Config.chainId)) { | |
| try { | |
| const chainHex = `${web3Config.chainId}`.toString('hex'); | |
| await window.ethereum.request({ | |
| method: 'wallet_switchEthereumChain', | |
| params: [{ chainId: `0x${chainHex}` }] | |
| }); | |
| } catch (err) { | |
| console.log(err); | |
| } | |
| throw new Error('Please try an connect again, on the right network.'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment