Skip to content

Commit

Permalink
Preserve browser URL path in verified contract
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Dec 14, 2021
1 parent 6b8eaf2 commit d3b6d07
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/hardhat-etherscan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,11 @@ Possible causes are:
);

if (verificationStatus.isVerificationSuccess()) {
const contractURL = new URL(
`/address/${address}#code`,
etherscanAPIEndpoints.browserURL
const contractURL = buildContractUrl(
etherscanAPIEndpoints.browserURL,
address
);

console.log(
`Successfully verified full build of contract ${contractInformation.contractName} on Etherscan.
${contractURL}`
Expand Down Expand Up @@ -746,9 +747,9 @@ subtask(TASK_VERIFY_VERIFY_MINIMUM_BUILD)
);

if (minimumBuildVerificationStatus.isVerificationSuccess()) {
const contractURL = new URL(
`/address/${address}#code`,
etherscanAPIEndpoints.browserURL
const contractURL = buildContractUrl(
etherscanAPIEndpoints.browserURL,
address
);
console.log(
`Successfully verified contract ${contractInformation.contractName} on Etherscan.
Expand Down Expand Up @@ -831,3 +832,9 @@ function isVersionRange(version: string): boolean {
version === METADATA_PRESENT_SOLC_NOT_FOUND_VERSION_RANGE
);
}

function buildContractUrl(browserURL: string, contractAddress: string): string {
const normalizedBrowserURL = browserURL.trim().replace(/\/$/, "");

return `${normalizedBrowserURL}/address/${contractAddress}#code`;
}

0 comments on commit d3b6d07

Please sign in to comment.