I’m working on a basic NFT minting app for a fundraiser. I set up the contracts on both Polygon and Ethereum testnets. But when I try to connect my frontend to the smart contracts using Ethers.js, I keep getting RPC errors about execution being reverted.
I’ve looked into it and tried some fixes I found online, but nothing seems to work. The error pops up on both networks. I’m using plain HTML for the frontend.
Here’s a snippet of my setup:
const nftApp = {
init: async function() {
if (window.ethereum) {
await window.ethereum.request({ method: 'eth_requestAccounts' });
console.log('Wallet connected');
} else {
console.log('Please install MetaMask');
}
},
mintToken: async function(tokenType) {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const nftContract = new ethers.Contract(NFT_ADDRESS, NFT_ABI, signer);
try {
const tx = await nftContract[`mint${tokenType}`]();
await tx.wait();
console.log(`${tokenType} token minted`);
} catch (error) {
console.error('Minting failed:', error);
}
}
};
nftApp.init();
Any ideas what might be causing this RPC error?
hey there FlyingEagle! wow, that’s so cool you’re working on an nft minting app for a fundraiser
i’ve been playing around with nfts too and ran into some similar issues. have you double-checked that your contract addresses and ABIs are correct for both networks? sometimes i mix those up and it causes weird errors.
also, just curious - are you able to connect to the networks and see your account balance in metamask? maybe there’s an issue with the network configuration?
oh, and another thing - do you have enough test ether/matic in your wallet to cover gas fees? i forgot about that once and kept getting errors 
let me know if any of that helps! i’d love to hear more about your project when you get it working. nfts for fundraising sounds like an awesome idea!
hey flyingeagle, had similar probs. check ur contract deployment - make sure it’s successful and address is right. also, try console.logging the error details. might give more clues.
have u tested the contract separately? could be an issue there. gl with ur fundraiser project, sounds cool!
Troubleshooting RPC errors can be tricky. Have you verified your smart contract is correctly deployed and initialized on both networks? Sometimes these errors occur due to contract state issues. Also, ensure your ABI is up-to-date with the deployed contract version.
Consider implementing more detailed error handling in your code. Instead of a generic catch, log the specific error message and stack trace. This can provide valuable insights into what’s actually failing.
Lastly, check if you’re hitting any rate limits with your RPC endpoint. If you’re using a public node, you might need to switch to a dedicated one or implement request throttling in your app.
Hope this helps. Good luck with your fundraising project.