Verify a contract extending OpenZeppelin Contracts with a constructor deployed from a factory?

I’m using hardhat to deploy the contract, is this correct?

async function main() {
// We get the contract to deploy
const Greeter = await ethers.getContractFactory(“CreateToken”);
const greeter = await Greeter.deploy(“Benjamin”, “benj”, 7, ‘0x16EDE61a09835D35e60D92AE0F11CF148cE262bF’, 3000000000);

console.log("Greeter deployed to:", greeter.address);

}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});

Because I’m getting this error below

Successfully submitted source code for contract
contracts/CreateToken.sol:CreateToken at 0x32220EF666E1054250e4f52f692C34a998220D0e
for verification on Etherscan. Waiting for verification result…
We tried verifying your contract CreateToken without including any unrelated one, but it failed.
Trying again with the full solc input used to compile and deploy it.
This means that unrelated contracts may be displayed on Etherscan…
Successfully submitted source code for contract
contracts/CreateToken.sol:CreateToken at 0x32220EF666E1054250e4f52f692C34a998220D0e
for verification on Etherscan. Waiting for verification result…
Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed.
Reason: Fail - Unable to verify

NomicLabsHardhatPluginError: The contract verification failed.
Reason: Fail - Unable to verify

1 Like

What I noticed is that if I try Remix and verify it using Remix verification plugin, it gets verified successfully but if I use truffle, I just cant get it verified.

1 Like

Hi @Benjamin_P,

I am not aware of anything different from verifying a contract deployed using Remix/Hardhat/Truffle and the same contract deployed using a factory contract.

You can verify using Hardhat even for contracts deployed elsewhere.

I just deployed with Hardhat and then verified with Hardhat to check that everything was working.

I deployed using Hardhat with the following script:

// scripts/deploy.js
async function main() {
    // We get the contract to deploy
    const CreateToken = await ethers.getContractFactory("CreateToken");
    console.log("Deploying Token...");
    const token = await CreateToken.deploy("Benj", "BEN", "7", "0x16EDE61a09835D35e60D92AE0F11CF148cE262bF", "1000000000000");
    await token.deployed();
    console.log("CreateToken deployed to:", token.address);
  }
  
  main()
    .then(() => process.exit(0))
    .catch(error => {
      console.error(error);
      process.exit(1);
    });

If you can deploy with Remix and verify with Remix, then that is ok. The important thing is to have appropriate testing and auditing.

Ok thanks for all the assistance.

1 Like