使用 Hardhat 在 EtherScan 上验证智能合约时出错

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

下面是我的智能合约(已部署)。当我尝试验证它以将代码提交到 Etherscan 时,我收到以下错误,我真的不知道为什么。请问有人可以建议吗?

 npx hardhat verify --network ropsten 0xE9abA803d6a801fce021d0074ae71256C9F24Da4

错误信息:

 Error in plugin @nomiclabs/hardhat-etherscan: More than one contract was found to match the deployed bytecode.
 Please use the contract parameter with one of the following contracts:
 * @openzeppelin/contracts/finance/PaymentSplitter.sol:PaymentSplitter
  * contracts/MyNFTContract.sol: MyNFTContract

 For example:

   hardhat verify --contract contracts/Example.sol:ExampleContract <other args>

 If you are running the verify subtask from within Hardhat instead:

   await run("verify:verify", {
     <other args>,
     contract: "contracts/Example.sol:ExampleContract"
  };

MyNFTContract.sol:

 // SPDX-License-Identifier: MIT
 pragma solidity ^0.8.0;

 import "@openzeppelin/contracts/finance/PaymentSplitter.sol";

 contract MyNFTContract is PaymentSplitter {
     // Addresses of payees
     address[] private _CSPayees = [
         0x23377d974d85C49E9CB6cfdF4e0EED1C0Fc85E6A,
         0x85F68F10d3c13867FD36f2a353eeD56533f1C751
     ];
     // Number of shares allocated per address in this contract.  In same order as _CSPayees
     uint256[] private _CSShares = [1, 2];

     constructor() PaymentSplitter(_CSPayees, _CSShares) {}
 }

我的部署脚本deploy.js:

 async function main() {
const PaymentSplitter = await ethers.getContractFactory("MyNFTContract")

// Start deployment, returning a promise that resolves to a contract object
const myNFT = await PaymentSplitter.deploy()
console.log("Contract deployed to address:", myNFT.address)
 }

 main()
.then(() => process.exit(0))
.catch((error) => {
    console.error(error)
    process.exit(1)
})
solidity smartcontracts openzeppelin hardhat
3个回答
13
投票

Hardhat 在项目中发现了多个合约(您的

MyNFTContract
和导入的
PaymentSplitter
),并且它不知道您要验证哪一个合约的字节码。

您需要使用

--contract
选项指定(您要验证的)合同。

npx hardhat verify \
--contract "contracts/MyNFTContract.sol" \
--network ropsten 0xE9abA803d6a801fce021d0074ae71256C9F24Da4

0
投票

我导入了这些

require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan"); 

并且成功了


0
投票

您遇到的此错误消息是因为安全帽在您的合同文件中发现了多个合同,因此您必须指定要验证的合同以指定您可以将合同添加到您的运行中。

等待运行(“验证:验证”,{ 地址:合约地址, 构造函数参数: args, 合约:“contracts/OurToken.sol:OurToken” }

© www.soinside.com 2019 - 2024. All rights reserved.