0

I tried to verify contract in polygon mumbai!

Harhat version: ^2.15.0

  const hre = require("hardhat");


  const ETHERSCAN_API_KEY = ""
  async function  deploy(){

  const simpleStorageFactory = await hre.ethers.deployContract("SimpleStorage");
  await simpleStorageFactory.waitForDeployment();
  console.log("simpleStorageFactory",await simpleStorageFactory)
  console.log("Deploying....");
  console.log(`Deployed contract to ${await simpleStorageFactory.getAddress() }`)


  if(hre.network.config.chainId === 80001 && ETHERSCAN_API_KEY ){
    console.log("waiting for confirmation")
    await simpleStorageFactory.deploymentTransaction(6);
    await verify(await simpleStorageFactory.getAddress(),[])
  }

  const currentValue = await simpleStorageFactory.retrieve();
  console.log(`Current Valur is: ${currentValue}`);

  // update value
  const transactionResponse = await simpleStorageFactory.store(10);
  await transactionResponse.wait(1);
   const newCurrentValue = await simpleStorageFactory.retrieve();
   console.log(`Newly update current value is ${newCurrentValue}`)

}

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

  }
}

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

when calling verify(), running into issue:

Contract Verification Error:  ContractVerificationMissingBytecodeError: Failed to send contract verification request.
Endpoint URL: https://api-testnet.polygonscan.com/api
Reason: The Etherscan API responded that the address 0x8F90aeB399FcA8A7F30B41e7613040b49a0Dd169 does not have bytecode.
This can happen if the contract was recently deployed and this fact hasn't propagated to the backend yet.
Try waiting for a minute before verifying your contract. If you are invoking this from a script,
try to wait for five confirmations of your contract deployment transaction before running the verification subtask.
    at Etherscan.verify (/workspace/hardhat-simple-storage/node_modules/@nomicfoundation/hardhat-verify/src/etherscan.ts:108:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at SimpleTaskDefinition.action (/workspace/hardhat-simple-storage/node_modules/@nomicfoundation/hardhat-verify/src/index.ts:468:33)
    at Environment._runTaskDefinition (/workspace/hardhat-simple-storage/node_modules/hardhat/src/internal/core/runtime-environment.ts:330:14)
    at Environment.run (/workspace/hardhat-simple-storage/node_modules/hardhat/src/internal/core/runtime-environment.ts:163:14)
    at SimpleTaskDefinition.action (/workspace/hardhat-simple-storage/node_modules/@nomicfoundation/hardhat-verify/src/index.ts:295:9)
    at Environment._runTaskDefinition (/workspace/hardhat-simple-storage/node_modules/hardhat/src/internal/core/runtime-environment.ts:330:14)
    at Environment.run (/workspace/hardhat-simple-storage/node_modules/hardhat/src/internal/core/runtime-environment.ts:163:14)
    at SimpleTaskDefinition.action (/workspace/hardhat-simple-storage/node_modules/@nomicfoundation/hardhat-verify/src/index.ts:544:7)
    at Environment._runTaskDefinition (/workspace/hardhat-simple-storage/node_modules/hardhat/src/internal/core/runtime-environment.ts:330:14)
2
  • Make sure to wait for few blocks after deployment. Also try verifying via CLI if that works, means API is working fine and there is some error in your script. Commented Jun 30, 2023 at 5:51
  • what's the error?
    – Karthick
    Commented Jun 30, 2023 at 17:35

2 Answers 2

1

As the error code suggests, you should wait for a certain number of network confirmations before verifying a contract.

On your code snippet, I can see you are trying to deploy and verify on Mumbai, which typically requires between 5 and 10 confirmations before the bytecode of a recently deployed contract is propagated across the network.

You are currently intending to wait for 6 confirmations via this line:

await simpleStorageFactory.deploymentTransaction(6);

Doing it like this instead should solve the issue:

await simpleStorageFactory.deploymentTransaction().wait(10);

Dependencies version I'm using:

"hardhat": "^2.17.3"
"@nomicfoundation/hardhat-toolbox": "^3.0.0"
"@nomicfoundation/hardhat-verify": "^1.0.0"

Cheers!

0

I suspected it is just that you need to wait up to a few minutes(ideally) but for polygonscan to index the deployment data before the contract verification it sometimes take a lot more time (days too !).

Meanwhile try using Hardhat-verify to be sure that there's nothing wrong with your script

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.