0

There's a button for minting an NFT on my website. Somebody, during a test, when trying to mint a token was using a wrong network -- Ethereum mainnent instead of Arbitrum Goerli. And a TX got through without any error, although no NFT got minted.

Is there a way to prevent or warn a user, when a mint(..) is about to get called that a wrong network is being used, if it's a wrong one indeed?

I'm using ethers.js

1 Answer 1

0

You can get the chain id from the signer object which you pass to the contract instance i.e. var contract = new ethers.Contract(address,abi,signer) You can use var chainID = await signer.getChainId() to get the chain id of the connected chain use if else to check if the connected chain is correct or not and show an alert or proceed with the transaction accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.