Skip to content

Commit

Permalink
Improve error and add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
schaable committed May 6, 2024
1 parent 640dd2d commit b9aada0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-goats-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/hardhat-verify": patch
---

Added 'force' flag to allow verification of partially verified contracts (thanks @rimrakhimov!)
9 changes: 4 additions & 5 deletions packages/hardhat-verify/src/internal/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,9 @@ ${undetectableLibraries.map((x) => ` * ${x}`).join("\n")}`
}

export class ContractAlreadyVerifiedError extends HardhatVerifyError {
constructor(contractAddress: string) {
super(`The Etherecan API responded that the contract ${contractAddress} is already verified.
This can happen if you used '--force' flag, but either the explorer does not support contracts' re-verification
(e.g., Etherscan) or the contract has already been verified with a full match.`);
Object.setPrototypeOf(this, ContractAlreadyVerifiedError.prototype);
constructor(contractFQN: string, contractAddress: string) {
super(`The block explorer's API responded that the contract ${contractFQN} at ${contractAddress} is already verified.
This can happen if you used the '--force' flag. However, re-verification of contracts might not be supported
by the explorer (e.g., Etherscan), or the contract may have already been verified with a full match.`);
}
}
2 changes: 1 addition & 1 deletion packages/hardhat-verify/src/internal/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class Etherscan {
}

if (etherscanResponse.isAlreadyVerified()) {
throw new ContractAlreadyVerifiedError(contractAddress);
throw new ContractAlreadyVerifiedError(contractName, contractAddress);
}

if (!etherscanResponse.isOk()) {
Expand Down
7 changes: 4 additions & 3 deletions packages/hardhat-verify/src/internal/tasks/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,17 @@ subtask(TASK_VERIFY_ETHERSCAN_ATTEMPT_VERIFICATION)
// Ensure the linking information is present in the compiler input;
compilerInput.settings.libraries = contractInformation.libraries;

const contractFQN = `${contractInformation.sourceName}:${contractInformation.contractName}`;
const { message: guid } = await verificationInterface.verify(
address,
JSON.stringify(compilerInput),
`${contractInformation.sourceName}:${contractInformation.contractName}`,
contractFQN,
`v${contractInformation.solcLongVersion}`,
encodedConstructorArguments
);

console.log(`Successfully submitted source code for contract
${contractInformation.sourceName}:${contractInformation.contractName} at ${address}
${contractFQN} at ${address}
for verification on the block explorer. Waiting for verification result...
`);

Expand All @@ -321,7 +322,7 @@ for verification on the block explorer. Waiting for verification result...

// Etherscan answers with already verified message only when checking returned guid
if (verificationStatus.isAlreadyVerified()) {
throw new ContractAlreadyVerifiedError(address);
throw new ContractAlreadyVerifiedError(contractFQN, address);
}

if (!(verificationStatus.isFailure() || verificationStatus.isSuccess())) {
Expand Down

0 comments on commit b9aada0

Please sign in to comment.