Solidity – How to Verify a Smart Contract Generated by Another Contract with Arguments on Etherscan Using Hardhat

etherscanfactoryhardhatsolidityverify

I've created a contract factory smart contract and deployed + verified on Ropsten.

How can I verify the child-contracts on etherscan?

Parent contract: https://ropsten.etherscan.io/address/0xa3b82dc5b961405ba45d1a2f7f35ebe40b1d7ecc

Child contract: https://ropsten.etherscan.io/address/0x95BbFBA0E67Bc56dd9979Bd5BB069EB971FDFe63#code

  1. I've attempted to use the hardhat-etherscan plugin to auto-verify:

npx hardhat verify --network ropsten 0x95BbFBA0E67Bc56dd9979Bd5BB069EB971FDFe63 "Satoshiris" "SATUSI"

  1. I've attempted to manually verify by using hardhat flatten command to then input that into the UI on etherscan.

npx hardhat flatten > flattened.sol

Any help is appreciated.

Best Answer

The right syntax for verifying a contract that has more than one parameter in hardhat is by using --contructor-args flag. Please check doc for reference. https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan#complex-arguments

If the intention is to get a green tick and the source code of the contract to be displayed on all new instance of the child contract on etherscan, you can do the following.

Firstly, deploy only the child contract with some dummy arguments and verify it.

You can deploy only the child contract by adding the child contract name in hardhat's getContractFactory function. (Or if you are using remix, you can select it under the dropdown.)

  const child = await hre.ethers.getContractFactory("NFTToken");

Once it's deployed verify the deployed child contract.

npx hardhat verify --network ropsten 0x95BbFBA0E67Bc56dd9979Bd5BB069EB971FDFe63 --constructor-args arguments.js

Next, you can deploy and verify the Factory contract.

Now, whenever a new instance of a child contract is created you can see the message 'Similar Match Source Code' on etherscan and you can see the contract source code, since the contract with the same byte code is already verified!. You can see green tick and source code but, this doens't mean that the contract is verified.

Related Topic