Skip to content

Commit

Permalink
Fix hardcoded URL in the etherscan plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Mar 1, 2023
1 parent e51bb21 commit 6ecb74d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/hardhat-etherscan/src/etherscan/EtherscanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,21 @@ export class EtherscanResponse {
}

export async function isAlreadyVerified(
apiURL: string,
apiKey: string,
address: string
): Promise<boolean> {
const url = `https://api.etherscan.io/api?module=contract&action=getsourcecode&address=${address}&apikey=${apiKey}`;
const parameters = new URLSearchParams({
module: "contract",
action: "getsourcecode",
address,
apikey: apiKey,
});

const response = await sendGetRequest(new URL(url));
const url = new URL(apiURL);
url.search = parameters.toString();

const response = await sendGetRequest(url);
const json = await response.body.json();

if (json.message !== "OK") {
Expand Down
8 changes: 7 additions & 1 deletion packages/hardhat-etherscan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ If your constructor has no arguments pass an empty array. E.g:
verificationNetwork
);

if (await isAlreadyVerified(etherscanAPIKey, address)) {
const alreadyVerified = await isAlreadyVerified(
etherscanAPIEndpoints.apiURL,
etherscanAPIKey,
address
);

if (alreadyVerified) {
console.log(`The contract ${address} has already been verified`);
return;
}
Expand Down

0 comments on commit 6ecb74d

Please sign in to comment.