Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for verification on the block explorer. Waiting for verification result... #5858

Open
wjh-x opened this issue Oct 26, 2024 · 5 comments
Open
Assignees
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@wjh-x
Copy link

wjh-x commented Oct 26, 2024

Hello everyone, I encountered a problem where the deployment contract verification failed.
For example, the second BaseRegistrarImplementation contract needs to use the address of the first ENSRegistry contract. The first contract can be verified normally on the browser, but the second contract is always waiting. Below is my project information. Please help me. Thank you.

package.json
{ "devDependencies": { "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", "@nomicfoundation/hardhat-ethers": "^3.0.8", "@nomicfoundation/hardhat-ignition": "^0.15.0", "@nomicfoundation/hardhat-ignition-ethers": "^0.15.0", "@nomicfoundation/hardhat-network-helpers": "^1.0.0", "@nomicfoundation/hardhat-toolbox": "^5.0.0", "@nomicfoundation/hardhat-verify": "^2.0.11", "@typechain/ethers-v6": "^0.5.0", "@typechain/hardhat": "^9.0.0", "chai": "^4.2.0", "ethers": "^6.13.4", "hardhat": "^2.22.14", "hardhat-gas-reporter": "^1.0.8", "solidity-coverage": "^0.8.0", "typechain": "^8.3.0" }, "packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610", "dependencies": { "@ensdomains/ens-contracts": "1.0.1", "dotenv": "^16.4.5", "hardhat-deploy": "^0.14.0", "undici": "^6.20.1", "viem": "^2.21.34" } }

hardhat.config.js
`require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-ethers");
require("hardhat-deploy");
require("dotenv").config();

const { ProxyAgent, setGlobalDispatcher } = require("undici");
const proxyAgent = new ProxyAgent("http://127.0.0.1:7890");
setGlobalDispatcher(proxyAgent);

const RPC_URL = process.env.RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const AMAZETEST_API_KEY = process.env.AMAZETEST_API_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
amazetest: {
url: RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 100100100,
},
amazemainnet: {
url: RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 94,
},
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
},
// etherscan: {
// apiKey: ETHERSCAN_API_KEY,
// },
etherscan: {
apiKey: {
amazetest: AMAZETEST_API_KEY,
},
customChains: [
{
network: "amazetest",
chainId: 100100100,
urls: {
apiURL: "https://testnet.amazechain.com/api",
browserURL: "https://testnet.amazechain.com/",
},
},
],
},
solidity: "0.8.27",
};
Below is my deploy.js codeconst { ethers, run, network } = require("hardhat");
const { namehash } = require("viem/ens");

async function main() {
// ENSRegistry
const eNSRegistryFactory = await ethers.getContractFactory(
"contracts/ens/ENSRegistry.sol:ENSRegistry"
);
console.log("deploy contract ENSRegistry...");
const eNSRegistry = await eNSRegistryFactory.deploy();
await eNSRegistry.waitForDeployment();
console.log(deploy contract to: ${eNSRegistry.target});

if (network.config.chainId === 100100100 && process.env.AMAZETEST_API_KEY) {
console.log("waitting for block taxes...");
await eNSRegistry.deploymentTransaction().wait(2);
await verify(
eNSRegistry.target,
[],
"contracts/ens/ENSRegistry.sol:ENSRegistry"
);
}

// BaseRegistrarImplementation
const baseNode = namehash("eth"); // 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae
// console.log(baseNode);
const baseRegistrarImplementationFactory = await ethers.getContractFactory(
"contracts/ens/BaseRegistrarImplementation.sol:BaseRegistrarImplementation"
);
console.log("deploy contract BaseRegistrarImplementation...");
const baseRegistrarImplementation =
await baseRegistrarImplementationFactory.deploy(
eNSRegistry.target,
baseNode
);
await baseRegistrarImplementation.waitForDeployment();
console.log(deploy contract to: ${baseRegistrarImplementation.target});

if (network.config.chainId === 100100100 && process.env.AMAZETEST_API_KEY) {
console.log("waitting for block taxes...");
await baseRegistrarImplementation.deploymentTransaction().wait(2);
await verify(
baseRegistrarImplementation.target,
[eNSRegistry.target, baseNode],
"contracts/ens/BaseRegistrarImplementation.sol:BaseRegistrarImplementation"
);
}
}

// 验证合约
async function verify(contractAddress, args, contractPath) {
console.log("verifying contract...");
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
contract: contractPath,
});
} catch (e) {
if (e.message.toLowerCase().includes("alreay verified")) {
console.log("already verified");
} else {
console.log(e);
}
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
This is my runyarn hardhat run scripts/deploy.js --network amazetest
yarn run v1.22.22
warning package.json: No license field
$ /Users/macbook/Desktop/wjh/blockchain/ens/node_modules/.bin/hardhat run scripts/deploy.js --network amazetest
deploy contract ENSRegistry...
deploy contract to: 0xD15f731a40aE1FBc6da1855686E1A63cc10Ec479
waitting for block taxes...
verifying contract...
The contract 0xD15f731a40aE1FBc6da1855686E1A63cc10Ec479 has already been verified on the block explorer. If you're trying to verify a partially verified contract, please use the --force flag.
https://testnet.amazechain.com/address/0xD15f731a40aE1FBc6da1855686E1A63cc10Ec479#code

deploy contract BaseRegistrarImplementation...
deploy contract to: 0x111549c39480AcF2C0E94a2cef4Cc0E355d334d9
waitting for block taxes...
verifying contract...
Successfully submitted source code for contract
contracts/ens/BaseRegistrarImplementation.sol:BaseRegistrarImplementation at 0x111549c39480AcF2C0E94a2cef4Cc0E355d334d9
for verification on the block explorer. Waiting for verification result...`

@kanej
Copy link
Member

kanej commented Nov 12, 2024

Are you able to verify if you do so via the command line rather than the script?

@kanej kanej added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Nov 12, 2024
@wjh-x
Copy link
Author

wjh-x commented Nov 14, 2024

Are you able to verify if you do so via the command line rather than the script?

Thank you for your reply. When I deployed successfully through the script but the verification failed and kept waiting, I forced it to end and verified it through the command line, but it was still stuck in a long wait.
Later I found that only when the deployment script requires parameters will it keep verifying and waiting, and when there are no parameters, it will succeed in the browser verification.

@kanej
Copy link
Member

kanej commented Nov 14, 2024

Are you able to verify if you do so via the command line rather than the script?

Thank you for your reply. When I deployed successfully through the script but the verification failed and kept waiting, I forced it to end and verified it through the command line, but it was still stuck in a long wait. Later I found that only when the deployment script requires parameters will it keep verifying and waiting, and when there are no parameters, it will succeed in the browser verification.

So you see the long wait, whether it goes through the programmatic API or at the cli.
However, it eventually did verify when run at the cli.

Can I confirm:

  • the long wait eventually ended when run against the cli, or did you have to end the execution manually?

@schaable where are the potential pauses in a verification with parameters?

@wjh-x
Copy link
Author

wjh-x commented Nov 14, 2024

Are you able to verify if you do so via the command line rather than the script?

Thank you for your reply. When I deployed successfully through the script but the verification failed and kept waiting, I forced it to end and verified it through the command line, but it was still stuck in a long wait. Later I found that only when the deployment script requires parameters will it keep verifying and waiting, and when there are no parameters, it will succeed in the browser verification.

So you see the long wait, whether it goes through the programmatic API or at the cli. However, it eventually did verify when run at the cli.

Can I confirm:

  • the long wait eventually ended when run against the cli, or did you have to end the execution manually?

@schaable where are the potential pauses in a verification with parameters?

If I don't stop manually and wait for a long time, an error will occur.
NetworkRequestError: A network request failed. This is an error from the block explorer, not Hardhat. Error: Connect Timeout Error
The following is an example of deployment. The first ENSRegistry contract does not require parameters and can be verified normally. The second BaseRegistrarImplementation contract requires the address of the first contract and a hash as parameters, so a wait occurs.
// ENSRegistry const eNSRegistryFactory = await ethers.getContractFactory( "contracts/ens/ENSRegistry.sol:ENSRegistry" ); console.log("deploy contract ENSRegistry..."); const eNSRegistry = await eNSRegistryFactory.deploy(); await eNSRegistry.waitForDeployment(); console.log(deploy contract to: ${eNSRegistry.target}`);

if (network.config.chainId === 100100100 && process.env.AMAZETEST_API_KEY) {
console.log("waitting for block taxes...");
await eNSRegistry.deploymentTransaction().wait(2);
await verify(
eNSRegistry.target,
[],
"contracts/ens/ENSRegistry.sol:ENSRegistry"
);
}

// BaseRegistrarImplementation
const baseNode = namehash("eth");
const baseRegistrarImplementationFactory = await ethers.getContractFactory(
"contracts/ens/BaseRegistrarImplementation.sol:BaseRegistrarImplementation"
);
console.log("deploy contract BaseRegistrarImplementation...");
const baseRegistrarImplementation =
await baseRegistrarImplementationFactory.deploy(
eNSRegistry.target,
baseNode
);
await baseRegistrarImplementation.waitForDeployment();
console.log(deploy contract to: ${baseRegistrarImplementation.target});

if (network.config.chainId === 100100100 && process.env.AMAZETEST_API_KEY) {
console.log("waitting for block taxes...");
await baseRegistrarImplementation.deploymentTransaction().wait(2);
await verify(
baseRegistrarImplementation.target,
[eNSRegistry.target, baseNode],
"contracts/ens/BaseRegistrarImplementation.sol:BaseRegistrarImplementation"
);
}`

@schaable
Copy link
Member

@schaable where are the potential pauses in a verification with parameters?

The verification task polls for the verification status after sending the verification request to Etherscan. However, the error you're encountering seems to point to a network issue rather than a pause during verification.

To validate this, I’ve created an example with two contracts. In this setup, one contract receives the address of the other as a constructor argument and initializes it. Then, I wrote a script to deploy and verify both contracts:

// Storage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

contract Storage {
    uint256 private value;

    function setValue(uint256 _value) external {
        value = _value;
    }

    function getValue() external view returns (uint256) {
        return value;
    }
}
// Manager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "./Storage.sol";

contract Manager {
    Storage private storageContract;

    constructor(address _storageAddress) {
        storageContract = Storage(_storageAddress);
    }

    function updateStorageValue(uint256 _value) external {
        storageContract.setValue(_value);
    }

    function retrieveStorageValue() external view returns (uint256) {
        return storageContract.getValue();
    }
}
// scripts/deploy.ts
import { ethers, run } from "hardhat";

async function main() {
  // Deploy Storage contract
  const Storage = await ethers.getContractFactory("Storage");
  const storage = await Storage.deploy();
  await storage.deploymentTransaction()?.wait(5);
  const storageContractAddress = await storage.getAddress();
  console.log("Storage deployed to:", storageContractAddress);

  // Deploy Manager contract with Storage contract address
  const Manager = await ethers.getContractFactory("Manager");
  const manager = await Manager.deploy(storageContractAddress);
  await manager.deploymentTransaction()?.wait(5);
  const managerContractAddress = await manager.getAddress();
  console.log("Manager deployed to:", managerContractAddress);

  await verify(storageContractAddress, [], "contracts/Storage.sol:Storage");
  await verify(
    managerContractAddress,
    [storageContractAddress],
    "contracts/Manager.sol:Manager"
  );
}

async function verify(
  address: string,
  constructorArguments: any[],
  contract: string
) {
  console.log("Verifying contract", contract, "at address", address);
  try {
    await run("verify:verify", {
      address,
      constructorArguments,
      contract,
    });
  } catch (error) {
    console.error(error);
  }
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

The script works correctly when deploying to the Sepolia network:

➜ npx hardhat run scripts/deploy.ts --network sepolia
Storage deployed to: 0xcB4ad50602DC86d7BB14E4012148c70FB0aeBA14
Manager deployed to: 0x597029E29AAe7b042Da0D7690cea12eDd64F9CDc
Verifying contract contracts/Storage.sol:Storage at address 0xcB4ad50602DC86d7BB14E4012148c70FB0aeBA14
The contract 0xcB4ad50602DC86d7BB14E4012148c70FB0aeBA14 has already been verified on the block explorer. If you're trying to verify a partially verified contract, please use the --force flag.
https://sepolia.etherscan.io/address/0xcB4ad50602DC86d7BB14E4012148c70FB0aeBA14#code

Verifying contract contracts/Manager.sol:Manager at address 0x597029E29AAe7b042Da0D7690cea12eDd64F9CDc
The contract 0x597029E29AAe7b042Da0D7690cea12eDd64F9CDc has already been verified on the block explorer. If you're trying to verify a partially verified contract, please use the --force flag.
https://sepolia.etherscan.io/address/0x597029E29AAe7b042Da0D7690cea12eDd64F9CDc#code

@wjh-x can you try deploying to Sepolia to check if you still encounter the same error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Status: Backlog
Development

No branches or pull requests

4 participants
@kanej @schaable @wjh-x and others