Problems with NFT minting script - seeking advice

I’m in the process of writing a script to mint NFTs but I’m facing some challenges. Most of it seems to be functioning correctly, but I hit a wall when trying to complete the final minting step. The script should communicate with my already deployed contract and generate the NFT in my wallet, but it continuously fails.

// scripts/nftMinting.js
require("dotenv").config({ path: './settings.env' });
const { ethers } = require("ethers");

const nftContract = require("../compiledContracts/MyUniqueNFT.sol/MyUniqueNFT.json");
const nftABI = nftContract.abi;

const provider = ethers.getDefaultProvider("sepolia", {
  alchemy: process.env.ALCHEMY_KEY,
});

const myWallet = new ethers.Wallet(process.env.MY_PRIVATE_KEY, provider);

const uniqueNFT = new ethers.Contract(
  process.env.NFT_CONTRACT_ADDRESS,
  nftABI,
  myWallet
);

const runMinting = () => {
  uniqueNFT
    .mintToken(process.env.MY_PUBLIC_KEY)
    .then((txnResult) => console.log(txnResult))
    .catch((err) => console.log("minting encountered an error", err));
};

runMinting();

I’m getting this strange quorum error related to estimateGas and SERVER_ERROR. The contract address I provided should be correct since it corresponds to my successful deployment. I also encountered some issues with the path to the environment file, which I believe I managed to resolve. Can anyone help me figure out what’s behind this gas estimation issue?

had this exact probs last week! the issue’s prob ur .env file path - just remove the path param and place the .env file in ur root dir. also check that MY_PUBLIC_KEY is ur actual wallet addr, not the literal public key. sepolia’s finicky with gas estimation too, so try adding gasLimit: 500000 to ur txn options.

That SERVER_ERROR during gas estimation usually means your transaction would fail. Your contract probably has access controls or minting requirements you’re not meeting. I’ve hit this exact issue when my contract needed the caller to have a specific role or when minting limits were active. First, try calling your contract’s view functions to make sure the connection works. Then check if your wallet has the right permissions to mint. You can also run estimateGas on the mintToken call separately - it’ll give you a clearer error message about why it’s failing. Also double-check that your contract’s mintToken function matches what you’re calling. Some need extra parameters like token metadata or use completely different function names.

That gas estimation error is super frustrating! I’ve hit similar issues and they’re a pain to debug :thinking:

First - are you passing extra parameters to mintToken? Some contracts need a tokenURI or metadata hash with the recipient address. What’s your contract’s mintToken function signature?

Also, check if you’ve got enough Sepolia ETH. Sounds basic but I’ve been caught by this before lol. Verify your balance and try setting the gas limit manually to bypass the estimation.

Another thing - is the contract actually deployed on Sepolia? Try calling a simple view function first (totalSupply or owner) to confirm the contract works before minting.

What’s the exact error message? More details on that SERVER_ERROR would help us troubleshoot!