enter image description hereI am trying to mint an NFT using a contract deployed on the Ethereum network. I have written a JavaScript code mint-nft.js, that uses the @alch/alchemy-web3 library to interact with the contract. However, when I try to execute the mintNFT() function with a valid token URI, I receive the following error:

"Something went wrong when submitting your transaction: Error: Transaction has been reverted by the EVM."

This is my mint-nft.js

require("dotenv").config({path:"../.env"});//empty dotenv wasn't working so add the path
const API_URL = process.env.API_URL;

const PUBLIC_KEY = process.env.PUBLIC_KEY;
// console.log(`public key`,PUBLIC_KEY)
const PRIVATE_KEY = process.env.PRIVATE_KEY;
// console.log(`private key`,PRIVATE_KEY)
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(API_URL);

const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json");

// console.log(JSON.stringify(contract.abi));

const contractAddress = process.env.DEPLOYED_CONTRACT_ADDRESS;
// console.log(`contract address`,contractAddress)
const nftContract = new web3.eth.Contract(contract.abi, contractAddress);
// console.log(`nftContract`,nftContract)

async function mintNFT(tokenURI) {
  try {
    const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, "latest");
    console.log(`nonce is `,nonce);

    const tx = {
      from: PUBLIC_KEY,
      to: contractAddress,
      nonce: nonce,
      gas: 500000,
      data: nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI(),

    const signedTx = await web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
    console.log(`signedTx is `,signedTx)
    const { rawTransaction } = signedTx;
    console.log(`rawTransaction is `,rawTransaction)
    const receipt = await web3.eth.sendSignedTransaction(rawTransaction);
    console.log(`reciept is `,receipt)
      "The hash of your transaction is: ",
      "\nCheck Alchemy's Mempool to view the status of your transaction!"
  } catch (error) {
    console.log("Something went wrong when submitting your transaction:", error);

mintNFT(process.env.URL_METADATA_PINATA)//this is the URL of nft-metadata.json

enter image description here

  • It would be helpful if you could paste the transactionHash (not within image) so we can copy and cross check
    – donoso.eth
    Apr 15, 2023 at 6:09

1 Answer 1


Hey tarun can u share the full error screeenshot.

I think most possible error is the gas limit you are providing is less for the function. The Whole limit is been utlilized and so the tx is getting failed

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.