solidity - 使用 Hardhat 在 EtherScan 上验证智能合约时出错
问题描述
下面是我的智能合约(已经部署)。当我尝试验证它以将代码提交给 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)
})
解决方案
Hardhat 在项目中发现了多个合约(您的MyNFTContract
和导入的PaymentSplitter
),它不知道您要针对哪个合约来验证字节码。
您需要使用该选项指定合同(您要验证的)--contract
。
npx hardhat verify \
--contract "contracts/MyNFTContract.sol" \
--network ropsten 0xE9abA803d6a801fce021d0074ae71256C9F24Da4
推荐阅读
- c# - 如何在 OnModelCreating 中减少 Fluent API 的代码
- python - 如何设置对象的 UV 纹理坐标并使用 python 计算切线空间?
- go - 如何从多个 goroutine 共享的单个通道中读取
- sql-server - SQL Server 位数组
- youtube-api - Youtube API V3;视频的最大数量只有 50?
- android - Adding fragment into framelayout cause support-actionbar hiding
- c++ - C ++ ostream没有创建新文件
- wpf - How to animate Button's Content property with Image control
- javascript - 如何区分nodejs中的文本文件和json文件
- docker - Cloud SQL 代理的 Docker 映像是什么?为什么要使用它?