0

I'm using hardhat to auto verify my contract, However, in await verify(simpleStorage.address, []), an error was reported:

Connect TimeoutError: Connect Timeout Error

const { ethers, run, network } = require("hardhat")
require("dotenv").config()

async function main() {
  const contractFactory = await ethers.getContractFactory("SimpleStorage")
  console.log("Deploying contract...")
  const simpleStorage = await contractFactory.deploy()
  await simpleStorage.deployed()
  console.log("Contract deployed to:", simpleStorage.address)
  console.log(network.config)
  if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
    await simpleStorage.deployTransaction.wait(6)
    await verify(simpleStorage.address, [])
  }
  const transactionResponse = await simpleStorage.addPerson("ws", 751)
  await transactionResponse.wait(1)
  const favoriteNumber = await simpleStorage.retrieve("ws")
  console.log(`Current value is: ${favoriteNumber}`)
}

async function verify(contractAddress, args) {
  console.log("Verifying contract...")
  try {
    await run("verify:verify", {
      address: contractAddress,
      constructorArgsParams: args,
    })
  } catch (e) {
    if (e.message.toLowerCase().includes("already verified")) {
      console.log("Already Verified!")
    } else {
      console.log(e)
    }
  }
}

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

here is my command and result: enter image description here

here is my hardhat.config.js:

module.exports = {
  solidity: "0.8.7",
  defaultNetwork: "sepolia",
  networks: {
    sepolia: {
      url: process.env.SEPOLIA_RPC_URL,
      accounts: [process.env.SEPOLIA_PRIVATE_KEY],
      chainId: 11155111,
    },
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY,
  },
}

and my package version is:

{
  "name": "hardhat-simple",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "2.0.4",
    "@nomiclabs/hardhat-etherscan": "^3.1.8",
    "@nomiclabs/hardhat-waffle": "2.0.2",
    "dotenv": "^16.3.1",
    "ethers": "5.5.3",
    "hardhat": "2.8.3",
    "prettier": "^3.1.1",
    "prettier-plugin-solidity": "^1.2.0"
  }
}

1
  • I think you should update the time-out of your project in hardhat-config or decrease the number of confirmation that you are waiting which is causing for Time-out,
    – Sham Gir
    Commented Apr 16 at 18:36

3 Answers 3

0

enter image description here

I solved this problem by referring to here

1
  • Link only answers are discouraged. It is better to include the main ideas in the answer an only use the link to expand the details.
    – Ismael
    Commented Dec 17, 2023 at 5:44
0

I have solved this issue by setting mocha timeout in hardhat.config.js

module.exports = {
...
  mocha: {
    timeout: 100000000 // or any time value that suits your project
  },
...
}
0

i have the same code, but an other error. and i don't know how to fix it.

eploying contract...
simple storage deployed: 0x6FF080a40b2205d943E5A7ca21d8C39908FDff7a
Verify contract...
NetworkRequestError: A network request failed. This is an error from the block explorer, not Hardhat. Error: Connect Timeout Error
    at Etherscan.isVerified (/Users/icanci/Solidity/Solidity-Learn-for-Hardhat/hardhat-simple-storage-fcc/node_modules/@nomicfoundation/hardhat-verify/src/internal/etherscan.ts:111:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at SimpleTaskDefinition.action (/Users/icanci/Solidity/Solidity-Learn-for-Hardhat/hardhat-simple-storage-fcc/node_modules/@nomicfoundation/hardhat-verify/src/internal/tasks/etherscan.ts:105:24)
1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Maka
    Commented Jun 18 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.