What's the correct way to create an NFT minting script?

I’ve been working on building an NFT minting script and running into some problems. I followed an online guide but it seems outdated and I’m stuck on the final minting step.

Here’s my current script:

// scripts/deploy-nft.js
require("dotenv").config();
const { ethers } = require("ethers");

const tokenABI = require("../artifacts/contracts/CoolCats.sol/CoolCats.json");
const contractABI = tokenABI.abi;

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

const userWallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, networkProvider);

const coolCatsContract = new ethers.Contract(
  process.env.DEPLOYED_CONTRACT_ADDRESS,
  contractABI,
  userWallet
);

const executeScript = () => {
  coolCatsContract
    .mintToken(process.env.WALLET_PUBLIC_KEY)
    .then((result) => console.log(result))
    .catch((error) => console.log("minting failed", error));
};

executeScript();

I’m getting a weird error about “quorum not met” when trying to estimate gas. The contract deployed successfully so I’m using that address. My environment variables are set up correctly but something is still breaking. Has anyone seen this kind of error before when minting NFTs? What could be causing the gas estimation to fail?

Hmm, interesting issue! Haven’t seen that exact “quorum not met” error when minting NFTs, but it’s probably related to gas estimation.

Quick question - are you passing any other parameters to your mintToken function besides the wallet address? Like token URI or metadata hash? Gas estimation sometimes fails if the function call isn’t complete.

Have you tried manually setting the gas limit? Add something like { gasLimit: 300000 } as a second parameter to your mintToken call - might bypass the estimation issue entirely.

Also, are you sure Goerli’s still active and your Alchemy endpoint is responding? Try getting your wallet balance first before minting, just to verify the connection works.

What does your actual mintToken function look like in the smart contract? That might give us a clue about what’s breaking the gas estimation.

that quorum error’s probably a network thing. goerli’s been flaky lately - switch to sepolia instead. your script’s also missing async/await, which messes up gas estimation timing. make executescript async and throw an await before the coolcatscontract.minttoken call.