无需验证与Hardhat的固定合同的etherscan

问题描述 投票:0回答:1

我正在尝试使用HardHat验证并将我的合同源代码提交给Etherscan,但我遇到了以下错误,我不明白如何解决该错误。我已经阅读了代码,但我无法发现自己在做什么。请有人建议吗?

我运行时遇到的错误:

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

eRROR消息:

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"
    )

您的合同没有构造函数参数,这就是为什么通过参数使任务失败的原因。试试看:
blockchain solidity smartcontracts hardhat etherscan
1个回答
6
投票

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.