Unable to verify a contract on hardhat

Getting this error when trying to verify on Hardhat TypeError: Cannot read property 'contracts' of undefined. Seems like I followed this tutorial Verify smart contract inheriting from OpenZeppelin Contracts correctly. Maybe a syntax problem due to multiple arguments in the constructor?

:computer: Environment
“hardhat”: “^2.0.2”
solidity: ^0.6.6;

:memo:Details

:1234: Code to reproduce
Here is the code I run in the terminal npx hardhat verify --network rinkeby 0xA4630A1f2DaC2474d7397E7e8F3A41Bd574C1f9d 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B 0x01BE23585060835E02B77ef475b0Cc51aA1e0709 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311
for the constructor

constructor(
      address _vrfCoordinator,
      address _linkToken,
      bytes32 _keyHash)
      public
      VRFConsumerBase(_vrfCoordinator, _linkToken)
      ERC721("DungeonsAndDragonsCharacter", "D&D")
  {        vrfCoordinator = _vrfCoordinator;
           keyHash = _keyHash;
           fee = 0.1 * 10**18; //0.1 LINK
  }
1 Like

I am not sure, maybe you should use " to declare the constructor parameters, eg:

npx hardhat verify --network rinkeby DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"

but it may not work, so I recommend you try to use a arguments.js file like this:

module.exports = [
  Constructor argument 1,
  Constructor argument 2,
  Constructor argument 3,
];

For more details, you can find at here: hardhat-etherscan

1 Like

I’ve tried it. Does not seem to work. I dropped the question at the Hardhat discord. Not sure if they will respond. They never do lol.

1 Like

FYI, Running into this when I try to verify using arguments.js

$ npx hardhat verify --constructor-args arguments.js 0xA4630A1f2DaC2474d7397E7e8F3A41Bd574C1f9d
Nothing to compile
Error in plugin @nomiclabs/hardhat-etherscan: Value 1.0268332219058108e+48 cannot be encoded for the parameter _vrfCoordinator.
Encoder error reason: invalid address (argument="address", value=1.0268332219058108e+48, code=INVALID_ARGUMENT, version=address/5.0.5)```
                                                                                                                                                                    
module.exports = [    
    0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B,
    0x01BE23585060835E02B77ef475b0Cc51aA1e0709,
    0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311
  ];```

The arguments.js file is in the root of the project
1 Like

How about like this:

module.exports = [    
    "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B",
    "0x01BE23585060835E02B77ef475b0Cc51aA1e0709",
    "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311"
  ];
1 Like

I get this error when I use the quotes


TypeError: Cannot read property 'contracts' of undefined
    at SimpleTaskDefinition.action (D:\ETH\chainlink-nft-hardhat\node_modules\@nomiclabs\hardhat-etherscan\src\index.ts:711:29)
    at Environment._runTaskDefinition (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:217:35)
    at Environment.run (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:130:25)
    at SimpleTaskDefinition.verifySubtask [as action] (D:\ETH\chainlink-nft-hardhat\node_modules\@nomiclabs\hardhat-etherscan\src\index.ts:265:34)
    at Environment._runTaskDefinition (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:217:14)
    at Environment.run (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:130:14)
    at Environment._runTaskDefinition (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:217:14)
    at Environment.run (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\core\runtime-environment.ts:130:14)
    at main (D:\ETH\chainlink-nft-hardhat\node_modules\hardhat\src\internal\cli\cli.ts:188:5)```
1 Like

A little weird, I will have a try later.

1 Like

Hi @Altaergo,

Are you specifying a network?

with this syntax for specifying the network, am still not getting anything

Nothing to compile
Compiling 1 file with 0.6.6
An unexpected error occurred:

TypeError: Cannot read property 'contracts' of undefined```

I worked through Altaergo’s problem on discord.

It turns out it wasn’t anything code related, but it was something in npm and the packages he had installed.

I loaded his code into a new environment and was able to get it to verify.

Then he did the same thing and his code was able to verify.

So in summary, if something isn’t working, but should, you might want to start a fresh project and remove package dependencies you no longer rely on.

I also had to run
npx hardhat clean
before running
npx hardhat verify --network TESTrinkeby 0x474407a7d6aE50e86A3C0055338A5D5188Fea032 "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B" "0x01BE23585060835E02B77ef475b0Cc51aA1e0709" "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311"
in order to get it to verify.

4 Likes