From 6ecb74d94ed9e25380467e50cf77e88ea2656982 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Wed, 1 Mar 2023 17:51:36 -0300 Subject: [PATCH] Fix hardcoded URL in the etherscan plugin --- .../src/etherscan/EtherscanService.ts | 13 +++++++++++-- packages/hardhat-etherscan/src/index.ts | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts b/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts index e215dae127..698cc2050c 100644 --- a/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts +++ b/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts @@ -156,12 +156,21 @@ export class EtherscanResponse { } export async function isAlreadyVerified( + apiURL: string, apiKey: string, address: string ): Promise { - 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") { diff --git a/packages/hardhat-etherscan/src/index.ts b/packages/hardhat-etherscan/src/index.ts index 993bd902da..e61e7f1f32 100644 --- a/packages/hardhat-etherscan/src/index.ts +++ b/packages/hardhat-etherscan/src/index.ts @@ -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; }