NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.24k stars 1.39k forks source link

Verifying contracts. General exception occured when attempting to insert record. Please report this issue to the Hardhat team. #5709

Closed RaeII closed 1 month ago

RaeII commented 1 month ago

Version of Hardhat

2.22.6

What happened?

When I try to verify a contract, I get this error message:

Please report this issue to the Hardhat team.
Error Details: General exception occured when attempting to insert record
    at Etherscan.verify (/var/www/valocracy_rmrk/node_modules/@nomicfoundation/hardhat-verify/src/internal/etherscan.ts:199:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SimpleTaskDefinition.action (/var/www/valocracy_rmrk/node_modules/@nomicfoundation/hardhat-verify/src/internal/tasks/etherscan.ts:297:33)
    at async Environment._runTaskDefinition (/var/www/valocracy_rmrk/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
    at async Environment.run (/var/www/valocracy_rmrk/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
    at async SimpleTaskDefinition.action (/var/www/valocracy_rmrk/node_modules/@nomicfoundation/hardhat-verify/src/internal/tasks/etherscan.ts:155:7)
    at async Environment._runTaskDefinition (/var/www/valocracy_rmrk/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
    at async Environment.run (/var/www/valocracy_rmrk/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
    at async SimpleTaskDefinition.action (/var/www/valocracy_rmrk/node_modules/@nomicfoundation/hardhat-verify/src/index.ts:284:9)
    at async Environment._runTaskDefinition (/var/www/valocracy_rmrk/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)

However, it only happens with some contracts, not all of them.

This is the function I use for verification:

export async function deployValocracy(lpContractAddress:string) {

  console.log("\n-- VALOCRAZY --\n")

  const contractFactory = await ethers.getContractFactory('Valocrazy');

  const contract = await contractFactory.deploy() as unknown as Valocrazy;
  await contract.waitForDeployment();
  const contractAddress = await contract.getAddress();

  console.log(`\nValocrazy deployed to -> ${contractAddress}\n\n`);

  const deploymentReceipt = await contract.deploymentTransaction()?.wait();
  // Calcula o custo do deploy
  let deploymentCost = 0;
  if(deploymentReceipt?.gasUsed && deploymentReceipt?.gasPrice){
    const gasUsed = deploymentReceipt?.gasUsed;
    const gasPrice = deploymentReceipt?.gasPrice;
    deploymentCost = Number(ethers.formatEther(gasUsed * gasPrice))

    console.log('Deployment cost:', deploymentCost)
  }

  if (!isHardhatNetwork()) {

    console.log('Waiting 60 seconds before verifying contract...');
    await delay(60000);
    await run('verify:verify', {
      address: contractAddress,
      // constructorArguments: args,
      contract: 'contracts/Valocrazy.sol:Valocrazy',
    });

  }

  console.log('\n====================\n\n')

  return {
    contract:contract,
    contractAddress:contractAddress,
    deploymentCost:deploymentCost
  };
}

Hardhat config

import { HardhatUserConfig } from 'hardhat/config';
//import 'dotenv/config';
import '@nomicfoundation/hardhat-ethers';
import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-contract-sizer';
import env from './src/config/index.ts'
// import './tasks/emotes';
// import './tasks/attributes';
// import './tasks/metadata';

const accounts = env.PRIVATE_KEY !== undefined ? [ env.PRIVATE_KEY] : [];

const config: HardhatUserConfig = {
  solidity: {
    version: '0.8.21',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },

  },

  networks: {
    hardhat: {
      allowUnlimitedContractSize: true,
      mining: {
        auto: false,
        interval: 5000
      }
    },
    moonbaseAlpha: {
      url: process.env.MOONBASE_URL || 'https://rpc.testnet.moonbeam.network',
      chainId: 1287,
      accounts: accounts,
      gasPrice: 1100000000, 
      allowUnlimitedContractSize: true,
      timeout:60000
    },
    sepolia: {
      url: process.env.SEPOLIA_URL || 'https://rpc.sepolia.dev',
      chainId: 11155111,
      accounts: accounts,
    },
    polygonMumbai: {
      url: process.env.MUMBAI_URL || 'https://rpc-mumbai.maticvigil.com',
      chainId: 80001,
      accounts: accounts,
      gasPrice: 2500000000,
    },
    baseGoerli: {
      chainId: 84531,
      url: process.env.BASE_GOERLI_URL || 'https://goerli.base.org',
      accounts: accounts,
      gasPrice: 2000000000,
    },
    baseSepolia: {
      chainId: 84532,
      url: process.env.BASE_SEPOLIA_URL || 'https://sepolia.base.org',
      accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
      gasPrice: 900000000,
    },
    shibuya: {
      chainId: 81,
      url: process.env.SHIBUYA_URL || 'https://evm.shibuya.astar.network',
      accounts: accounts,
    },
    moonriver: {
      url: process.env.MOONRIVER_URL || 'https://rpc.api.moonriver.moonbeam.network',
      chainId: 1285,
      accounts: accounts,
    },
    moonbeam: {
      url: process.env.MOONBEAM_URL || 'https://rpc.api.moonbeam.network',
      chainId: 1284,
      accounts: accounts,
    },
    mainnet: {
      url: process.env.ETHEREUM_URL || 'https://eth.drpc.org',
      chainId: 1,
      accounts: accounts,
      gasPrice: 12000000000,
    },
    polygon: {
      url: process.env.POLYGON_URL || 'https://polygon.drpc.org',
      chainId: 137,
      accounts: accounts,
      gasPrice: 120000000000,
    },
    base: {
      chainId: 8453,
      url: process.env.BASE_URL || 'https://developer-access-mainnet.base.org',
      accounts: accounts,
    },
    astar: {
      url: process.env.ASTAR_URL || 'https://evm.astar.network',
      chainId: 592,
      accounts: accounts,
    },
    bsc: {
      url: process.env.BSC_URL || 'https://bsc-dataseed.bnbchain.org',
      chainId: 56,
      accounts: accounts,
      gasPrice: 3000000000,
    },
  },
  etherscan: {
    apiKey: {
      moonbaseAlpha: process.env.MOONSCAN_APIKEY || '', // Moonbeam Moonscan API Key
      sepolia: process.env.ETHERSCAN_API_KEY || '', // Sepolia Etherscan API Key
      polygonMumbai: process.env.POLYGONSCAN_API_KEY || '', // Polygon Mumbai Etherscan API Key
      baseGoerli: process.env.BASESCAN_API_KEY || '', // Base Goerli Etherscan API Key
      baseSepolia: process.env.BASESCAN_API_KEY || '', // Base Goerli Etherscan API Key
      shibuya: process.env.SHIBUYA_BLOCKSCOUT_API_KEY || '', // Shibuya blockscout API KeyT
      zkatana: process.env.ZKATANA_BLOCKSCOUT_API_KEY || '', // ZKatana blockscout API Key
      moonriver: process.env.MOONSCAN_APIKEY || '', // Moonriver Moonscan API Key
      moonbeam: process.env.MOONSCAN_APIKEY || '', // Moonbeam Moonscan API Key
      mainnet: process.env.ETHERSCAN_API_KEY || '', // Ethereum Etherscan API Key
      polygon: process.env.POLYGONSCAN_API_KEY || '', // Polygon Etherscan API Key
      base: process.env.BASESCAN_API_KEY || '', // Base Etherscan API Key
      astar: process.env.ASTAR_BLOCKSCOUT_API_KEY || '', // Astar blockscout API Key
      bsc: process.env.BSCSCAN_API_KEY || '', // BSC Etherscan API Key
    },
    customChains: [
      {
        network: 'baseGoerli',
        chainId: 84531,
        urls: {
          apiURL: 'https://api-goerli.basescan.org/api',
          browserURL: 'https://goerli.basescan.org',
        },
      },
      {
        network: 'baseSepolia',
        chainId: 84532,
        urls: {
          apiURL: 'https://api-sepolia.basescan.org/api',
          browserURL: 'https://sepolia.basescan.org',
        },
      },
      {
        network: 'base',
        chainId: 8453,
        urls: {
          apiURL: 'https://api.basescan.org/api',
          browserURL: 'https://basescan.org',
        },
      },
      {
        network: 'shibuya',
        chainId: 81,
        urls: {
          apiURL: 'https://shibuya.blockscout.com/api',
          browserURL: 'https://shibuya.blockscout.com/',
        },
      },
      {
        network: 'astar',
        chainId: 592,
        urls: {
          apiURL: 'https://astar.blockscout.com/api',
          browserURL: 'https://astar.blockscout.com/',
        },
      },
      {
        network: 'zkatana',
        chainId: 1261120,
        urls: {
          apiURL: 'https://zkatana.blockscout.com/api',
          browserURL: 'https://zkatana.blockscout.com',
        },
      },
    ],
  },

};

export default config;

My envs are all working fine.

Minimal reproduction steps

I'm deploying and verifying on the moobase-alpha network, which is the test network of Moonbeam.

I've already tried with flatten, but the error persists

Search terms

No response

neverm25 commented 1 month ago

image What's the isHardhatNetwork() function? And why did you comment the line for constructor argus?

RaeII commented 1 month ago

isHardhatNetwork() -> checks that it is not a hardhat local network I was just testing, that's why I commented it out, but the error is still happening anyway await run('verify:verify', { address: contractAddress, constructorArguments: args, contract: 'contracts/Valocrazy.sol:Valocrazy', });

RaeII commented 1 month ago

I deployed on the Sepolia network, and the verification worked, so I believe it might be an issue with the Moonbeam network

neverm25 commented 1 month ago

Yeah, it maybe.

simondlr commented 1 month ago

For what it's worth. I tried verifying a contract on Optimism Etherscan today that also threw this error and unsure how to debug it. Might be etherscan? Used to work in the past and changed nothing, so assuming that it's etherscan.

RaeII commented 1 month ago

I also believe the issue might be with Etherscan. I've contacted their support and am waiting for a response

dcposch commented 1 month ago

I've had the same issue with https://optimistic.etherscan.io/.

Encountered an error verifying this contract:
Response: `NOTOK`
Details: `General exception occured when attempting to insert record`

The same contracts (identical contracts, identical initcode, CREATE2-deployed to the same address) verify successfully on other chains including Arbitrum and Base.

I think the Etherscan's OP Mainnet instance may be bugged specifically.