johnDoe
johnDoe

Reputation: 795

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. 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:

 // 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:

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

Upvotes: 3

Views: 7722

Answers (3)

Nikhil Pandey
Nikhil Pandey

Reputation: 11

The error message that you are encountering is because hardhat found multiple contracts in your contract file; so, you have to specify which contract you want to verify to specify that you can add contract to you run:

await run("verify:verify", {
      address: contractAddress,
      constructorArguments: args,
      contract: "contracts/OurToken.sol:OurToken"
    }

Upvotes: 1

Iroh Nkechi Omolola
Iroh Nkechi Omolola

Reputation: 16

I imported these

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

and it worked

Upvotes: 0

Petr Hejda
Petr Hejda

Reputation: 43481

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.

You need to specify the contract (that you want to verify) with the --contract option.

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

Upvotes: 14

Related Questions