Skip to content

Instantly share code, notes, and snippets.

@Austinhs
Created December 2, 2022 22:43
Show Gist options
  • Select an option

  • Save Austinhs/9ce2c903021320da50a4b80def729526 to your computer and use it in GitHub Desktop.

Select an option

Save Austinhs/9ce2c903021320da50a4b80def729526 to your computer and use it in GitHub Desktop.
change network
// 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