How to verify a contract deployed by a factory contract

Hi @abcoathup

I think so too. And besides, I have another question about this kind of factory contract: How to Verify and Publish my contract source code which was deployed by the factory contract?
I've tried once but fail to verify the source code. The error message is "Error! Unable to generate Contract ByteCode and ABI". And the source code is from the factory contract that I've deleted the part of the factory contract code.

Ropsten Testnet
My tested factory contract: 0x146a476ff24711a59922Db59DD623423487dE5FC
My tested stakingreward contract which was deployed from factory contract:0x579BE9901cAFe8314C3D594987A0E8823EA108Ed

1 Like

Hi @uua,

When verifying you need to provide the parameters that were used to deploy the contract to verify.

info.stakingRewards = address(new StakingRewards(/*_rewardsDistribution=*/ address(this), rewardsToken, stakingToken));

I suggest using: https://github.com/nomiclabs/buidler/tree/master/packages/buidler-etherscan

1 Like

Thanks for your suggestion! It’s helpful.

1 Like

Hi @uua,

Let me know if you run into any issues.

Hi, @abcoathup
I’ve encountered an issue when I used a similar plugin like buidler called truffle-plugin-verify. While verifying the deployed contract, It fails to connect to Etherscan API at URL https://api-ropsten.etherscan.io/api.
So, there is a difference of API-KEYS between different network on ethereum? Can I use the same key to verify the contract?

1 Like

Hi @uua,

The Etherscan API key is usable across networks.

It looks like verifying factory contracts isn’t supported yet with truffle-plugin-verify:

I recommend using the Buidler plugin for now. I have a separate project that I use just for verification.

1 Like

Hi, @abcoathup
I’ve tried the example case on buidler and it did work to deploy a contract. But it still fails to request https://api-ropsten.etherscan.io/api with more error message “connect ETIMEDOUT” 31.13.90.33 while I used the buidler-etherscan plugin to verify the contract source code.
However, the status of this problem has a little different than the former way of truffle-plugin-verify that I can receive a report of API statistics.

error message:
Error in plugin @nomiclabs/buidler-etherscan: Failed to send contract verification request.
Endpoint URL: https://api-ropsten.etherscan.io/api
Reason: request to https://api-ropsten.etherscan.io/api failed, reason: connect ETIMEDOUT 31.13.90.33:443

Please help!

1 Like

Hi @uua,

I don’t know why you are getting this issue.

I just successfully verified a contract on Ropsten using the Buidler Etherscan plugin.

My buidler.config.js is as follows:

// buidler.config.js
const { projectId, mnemonic, apiKey } = require('./secrets.json');

usePlugin("@nomiclabs/buidler-etherscan");
usePlugin('@nomiclabs/buidler-ethers');

module.exports = {
    networks: {
        development: {
          url: "http://localhost:8545"
        },
        rinkeby: {
          url: `https://rinkeby.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        },
        ropsten: {
          url: `https://ropsten.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        },
        kovan: {
          url: `https://kovan.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        },
        goerli: {
          url: `https://goerli.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        },
        mainnet: {
          url: `https://mainnet.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        }
      },
    
    
    etherscan: {
        // Your API key for Etherscan
        // Obtain one at https://etherscan.io/
        apiKey: apiKey
      },
    solc: {
        version: "0.5.17"
      }
};
1 Like

Hi, @abcoathup
The configuration of mine is totally the same as you. I have no idea too.
According to the error message which I use “–show-stack-traces” to find, maybe there are some issues with the plugin of builder-etherscan. Or could you please have a look at the showed error messages?

Endpoint URL: https://api-ropsten.etherscan.io/api
Reason: request to https://api-ropsten.etherscan.io/api failed, reason: connect ETIMEDOUT 31.13.82.33:443
at verifyContract (C:\Users\Administrator\Desktop\test_buidler\node_modules\@nomiclabs\buidler-etherscan\src\etherscan\EtherscanService.ts:49:11)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at SimpleTaskDefinition.verify (C:\Users\Administrator\Desktop\test_buidler\node_modules\@nomiclabs\buidler-etherscan\src\index.ts:222:20)
at Environment._runTaskDefinition (C:\Users\Administrator\Desktop\test_buidler\node_modules\@nomiclabs\buidler\src\internal\core\runtime-environment.ts:203:14)
at main (C:\Users\Administrator\Desktop\test_buidler\node_modules\@nomiclabs\buidler\src\internal\cli\cli.ts:157:5)

Caused by: FetchError: request to https://api-ropsten.etherscan.io/api failed, reason: connect ETIMEDOUT 31.13.82.33:443
    at ClientRequest.<anonymous> (C:\Users\Administrator\Desktop\test_buidler\node_modules\node-fetch\lib\index.js:1461:11)
    at ClientRequest.emit (events.js:314:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
1 Like

BTW, how can I check out my Etherscan API key is correct that be abled to use to verify contract source code?

1 Like

You can logon to Etherscan and you can view your API key to check that it is correct.

I wonder if Windows is causing an issue. I recommend using WSL. Solidity Smart Contract development on Windows

Hi, I’ve found where the issue is. It’s a problem of network port that the PC’s port of 443 had been disable. So I can’t access etherscan API with port 443. I’m using another pc to verify and I found that builder.dev has been replaced with hardhat.org. Maybe I should use the latest version of “@nomiclabs/hardhat-etherscan” to try the verification operation.

2 Likes

Hi @uua,

Hardhat has just been released last week. I plan to update the Learn guides and my verification method over the next week or two.

1 Like

Sorry for reviving this one but I’d like to ask if you guys encountered an error such as this after running the npx buidler verify --network bscTest 0xf42186db970d2aca6de7c78119607ef8ef253463 --constructor-args arguments.js --show-stack-traces

An unexpected error occurred:

HardhatError: HH5: HardhatContext is not created.

I was able to verify the Factory contract but not the contract deployed by the factory.

hi, @Benjamin_P have you got the created contract address by the factory?

Is 0xf42186db970d2aca6de7c78119607ef8ef253463 the created contract? or the factory contract?

Hi,

It is the created contract by the factory. The address of the factory is 0x5F17cE4a9394A79b0e41ba514eC251fDd588C1C3 and it is verified successfully. I’m using BSC Testnet by the way.

Thanks

the error seems like the hardhat can't find your contract content which you created.
what's your file structure? Do you have a factory.sol and target.sol which is goint to be created?
Maybe you can try to deploy and verify the target contract seperately.

Ah, I used Truffle when I deployed it so it is located in the ./contracts.
The JSON or ABI is in ./client/src/contracts folder
I think this usual for Truffle but not Hardhat

so, have your problem fixed?

Hi,I meet the same issue here like
“Reason: request to https://api-rinkeby.etherscan.io/api failed, reason: connect ETIMEDOUT 66.220.151.20:443”
Could you tell me how to fix it? thx