From 75bed8dc31b60f4f6753056bc78766ffad89723a Mon Sep 17 00:00:00 2001 From: PhiMarHal <77635908+PhiMarHal@users.noreply.github.com> Date: Sun, 13 Oct 2024 18:10:18 +0200 Subject: [PATCH] Add network check on connectWallet() --- app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.js b/app.js index 21a5d32..9463003 100644 --- a/app.js +++ b/app.js @@ -519,6 +519,13 @@ async function connectWallet() { try { const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); userAddress = accounts[0]; + + // Check and switch to the correct network if necessary + if (!await checkAndSwitchNetwork()) { + // If the user didn't switch to the correct network, don't proceed + return false; + } + const web3Provider = new ethers.providers.Web3Provider(window.ethereum); const signer = web3Provider.getSigner(); contract = new ethers.Contract(CONFIG.CONTRACT_ADDRESS, CONFIG.CONTRACT_ABI, signer);