无法验证与 Etherscan 的 Hardhat 的可靠性合同

Unable to verify solidity contract with Hardhat for Etherscan

我正在尝试使用 hardhat 验证我的合约源代码并将其提交给 etherscan,但我 运行 遇到以下错误并且我不明白如何解决该错误。我已经通读了代码,但无法发现我做错了什么。请问有人可以指教吗?

我在 运行:

时遇到的错误

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

错误信息:

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

我的智能合约源文件(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);

}
}

我的脚本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"
)

您的合同没有构造函数参数,这就是传递参数导致任务失败的原因。试试这个:

npx hardhat verify --network ropsten 0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa