blockchainsoliditysmartcontractshardhatetherscan

Unable to verify solidity contract with Hardhat for Etherscan


I am trying to verify and submit my contract source code to etherscan using hardhat but I am running into the following error and I do not understand how to resolve the error. I have read through the code and I cannot spot what I am doing incorrectly. Please can someone advise?

The error that I am getting when I run:

npx hardhat verify --network ropsten 0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa 'MyNFTPrice!

ERROR MESSAGE:

Error in plugin @nomiclabs/hardhat-etherscan: The constructor for contracts/MyNFTPrice.sol:MyNFTPrice has 0 parameters but 1 arguments were provided instead.

My Smart contract source file (MyNFTPrice.sol):

    //Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
    import "@openzeppelin/contracts/utils/Counters.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

    contract MyNFTPrice is ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721("MyNFTPrice", "NFTPRICE") {}


    // Mint new NFT
    function mintNFT(address recipient, string memory tokenURI) public payable  {

        require(msg.value >= 50000000000000000, "You need 0.05 ETH to mint the NFT"); 

        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

    }
    }

My script MyNFTPrice.js:

     require("dotenv").config()
     const API_URL = process.env.API_URL
     const PUBLIC_KEY = process.env.PUBLIC_KEY
     const PRIVATE_KEY = process.env.PRIVATE_KEY

     const { createAlchemyWeb3 } = require("@alch/alchemy-web3")
     const web3 = createAlchemyWeb3(API_URL)

     const contract =    require("../artifacts/contracts/MyNFTPrice.sol/MyNFTPrice.json")
     const contractAddress = "0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa"
     const nftContract = new web3.eth.Contract(contract.abi, contractAddress)

     async function mintNFT(tokenURI) {
    const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, "latest") //get latest nonce

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

         const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY)
    signPromise
        .then((signedTx) => {
            web3.eth.sendSignedTransaction(
                signedTx.rawTransaction,
                function (err, hash) {
                    if (!err) {
                        console.log(
                            "The hash of your transaction is: ",
                            hash,
                            "\nCheck Alchemy's Mempool to view the status of your transaction!"
                        )
                    } else {
                        console.log(
                            "Something went wrong when submitting your transaction:",
                            err
                        )
                    }
                }
            )
        })
        .catch((err) => {
            console.log(" Promise failed:", err)
        })
    }

    mintNFT(
       "https://gateway.pinata.cloud/ipfs/QmZsdtYxMucNbTsEWxX5xNqTXvfwkEVUifiRrXJxYkHaaa"
    )

Solution

  • Your contract has no constructor parameters, that's why passing an argument is making the task fail. Try this instead:

    npx hardhat verify --network ropsten 0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa