简体   繁体   English

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

[英]Error Verifying smart contract on EtherScan using Hardhat

Below is my smart contract (already deployed).下面是我的智能合约(已经部署)。 When i try and verify it to submit the code to Etherscan I am getting the error below and I really don't know why.当我尝试验证它以将代码提交给 Etherscan 时,我收到以下错误,我真的不知道为什么。 Please can someone advise?请问有人可以建议吗?

 npx hardhat verify --network ropsten 0xE9abA803d6a801fce021d0074ae71256C9F24Da4

Error Message:错误信息:

 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: 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) {}
 }

My deploying script deploy.js:我的部署脚本 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)
})

Hardhat found multiple contracts in the project (your MyNFTContract and the imported PaymentSplitter ), and it doesn't know against which one you want to verify the bytecode. Hardhat 在项目中发现了多个合约(您的MyNFTContract和导入的PaymentSplitter ),并且它不知道您要根据哪个合约来验证字节码。

You need to specify the contract (that you want to verify) with the --contract option.您需要使用--contract选项指定合同(您要验证的合同)。

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

I imported these我导入了这些

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

and it worked它奏效了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Hardhat 部署智能合约时出错 - 错误 HH9:加载 Hardhat 的配置时出错 - Error deploying smart contract using Hardhat -- Error HH9: Error while loading Hardhat's configuration 使用安全帽编译智能合约时出错 - Errror compiling smart contract using hardhat 使用 Hardhat WITHOUT 脚本部署智能合约 - Deploying a smart contract using Hardhat WITHOUT script 使用安全帽部署智能合约时出错——无法读取 null 的属性“sendTransaction” - Error deploying smart contract using hardhat -- Cannot read property 'sendTransaction' of null 插件@nomiclabs/hardhat-etherscan 出错:合同验证失败。 原因:失败 - 无法验证 - 使用 arguments - Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed. Reason: Fail - Unable to verify - with arguments 将智能合约部署到本地安全帽节点时出错 - Error while deploying a smart contract to a local hardhat node 如何使用安全帽和以太币监控 Solidity 智能合约上的事件? - How to monitor events on an Solidity Smart Contract using hardhat and ethers? 在Etherscan上验证松露合约时发生ParserError - ParserError when verifying Truffle contract on Etherscan 使用 HardHat 访问智能合约公共变量的最佳方式是什么? - what is the best way to access smart contract public variables using HardHat? 在 Etherscan Rinkeby 上验证/发布智能合约 - Verify/Publish Smart Contract on Etherscan Rinkeby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM