Skip to content

Commit

Permalink
Add network check on connectWallet()
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiMarHal authored Oct 13, 2024
1 parent a0f810f commit 75bed8d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 75bed8d

Please sign in to comment.