0

我正在尝试使用安全帽验证并将我的合同源代码提交给 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"
)
4

1 回答 1

3

您的合约没有构造函数参数,这就是为什么传递参数会使任务失败。试试这个:

npx hardhat verify --network ropsten 0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa
于 2021-09-20T13:46:34.513 回答