无法验证与 Hardhat for Etherscan 的可靠性合约
Posted
技术标签:
【中文标题】无法验证与 Hardhat for Etherscan 的可靠性合约【英文标题】:Unable to verify solidity contract with Hardhat for Etherscan 【发布时间】:2021-11-14 03:58:12 【问题描述】:我正在尝试使用安全帽验证我的合约源代码并将其提交到 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"
)
【问题讨论】:
【参考方案1】:您的合约没有构造函数参数,这就是为什么传递参数会使任务失败。试试这个:
npx hardhat verify --network ropsten 0xA16c8f9A5Ab944454D6404CE626E600AF0054aaa
【讨论】:
以上是关于无法验证与 Hardhat for Etherscan 的可靠性合约的主要内容,如果未能解决你的问题,请参考以下文章
使用Hardhat验证 Solidity 源码 (Ethereum or BSC)
无法使用 Powershell 正确安装安全帽!持续错误 HH12:尝试使用不支持的非本地安装的 Hardhat
Web3与智能合约:开发一个简单的DApp并部署到以太坊测试网(Solidity+Hardhat+React)① 环境搭建