Trouble minting NFT on Sepolia using Alchemy - Help needed!

Hey everyone,

I’m stuck trying to mint an NFT on Sepolia with Alchemy. Everything seemed fine until I ran node script/mint.js. Now I’m getting a 404 error. Here’s a snippet of what I’m seeing:

Error: server response 404 Not Found
code: 'SERVER_ERROR',
request: FetchRequest {},
response: FetchResponse {},
error: undefined

I’ve double-checked my API_URL and even asked AI for help, but no luck. Here’s a simplified version of my mint.js:

const { ethers } = require("ethers");

const contractStuff = require("../artifacts/contracts/nft.sol/nft.json");
const nftInterface = contractStuff.abi;

const alchemyConnect = new ethers.AlchemyProvider("sepolia", process.env.API_KEY);

const myWallet = new ethers.Wallet(process.env.SECRET_KEY, alchemyConnect);

const NFTContract = new ethers.Contract(process.env.NFT_ADDRESS, nftInterface, myWallet);

async function mintNFT() {
  try {
    const result = await NFTContract.mint(process.env.WALLET_ADDRESS);
    console.log(result);
  } catch (oops) {
    console.log("Uh-oh:", oops);
  }
}

mintNFT();

Any ideas what might be going wrong? I just want to mint my NFT without these hiccups. Thanks for any help!

hey sparklinggem, had similar issue. check ur API_KEY and NFT_ADDRESS. sometimes alchemy’s endpoints act up. try switching to a different rpc provider like infura or quicknode. also, make sure ur contract is deployed correctly on sepolia. good luck with ur nft project!

I encountered a similar issue when minting NFTs on Sepolia. The 404 error often indicates a problem with contract deployment or network configuration. First, verify your contract is properly deployed on Sepolia using a block explorer. Next, ensure your environment variables (API_KEY, NFT_ADDRESS, etc.) are correctly set and not expired. Consider using a try-catch block around the Contract initialization to catch any connection errors. Lastly, if the issue persists, try clearing your node_modules and reinstalling dependencies. Sometimes outdated or conflicting packages can cause unexpected errors in the minting process.

hey there sparklinggem! that 404 error can be super frustrating, i feel ya. have you double-checked that your NFT_ADDRESS is actually correct? sometimes a tiny typo can cause big headaches :sweat_smile:

also, im curious - when did you deploy your contract? if it was recent, maybe theres a sync delay with alchemy? ive seen that happen before

oh, and heres a thought - have you tried running your script with some console.log statements to see exactly where its failing? might help pinpoint the issue

let us know how it goes! nft minting can be tricky but once you get it working its super rewarding. what kind of nft are you making anyway?