Skip to content

Commit 5401a88

Browse files
authored
Merge pull request #6937 from NomicFoundation/verify-config-update
feat: enable providers by default and throw if apiKey is empty
2 parents a549e56 + 4d4e9f4 commit 5401a88

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

.changeset/wild-boats-study.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@nomicfoundation/hardhat-errors": patch
3+
"@nomicfoundation/hardhat-verify": patch
4+
"hardhat": patch
5+
---
6+
7+
Enable verification providers by default and throw if Etherscan apiKey is empty ([#6937](https://github.com/NomicFoundation/hardhat/pull/6937))

v-next/hardhat-errors/src/descriptors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,17 @@ chainDescriptors: {
26202620
websiteDescription: `The block explorer responded that the address does not contain a contract. This usually means the address is incorrect, the contract was not deployed on the selected network, or there is a temporary issue with the block explorer not updating its index.
26212621
Please verify the address and network, and try again later if necessary.`,
26222622
},
2623+
EXPLORER_API_KEY_EMPTY: {
2624+
number: 80030,
2625+
messageTemplate: `The {verificationProvider} API key is empty.`,
2626+
websiteTitle: "Block explorer API key is empty",
2627+
websiteDescription: `The provided API key for the block explorer is empty. This can happen in the following cases:
2628+
- No "apiKey" field is configured in the hardhat config.
2629+
- The "apiKey" is explicitly set to an empty string in the Hardhat config.
2630+
- The "apiKey" is assigned to a config variable that resolves to an empty string at runtime.
2631+
2632+
To resolve this, set a valid non-empty API key in your Hardhat config, then try again.`,
2633+
},
26232634
},
26242635
VALIDATION: {
26252636
INVALID_ADDRESS: {

v-next/hardhat-verify/src/internal/etherscan.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ export class Etherscan implements VerificationProvider {
5353
this.name = etherscanConfig.name ?? "Etherscan";
5454
this.url = etherscanConfig.url;
5555
this.apiUrl = ETHERSCAN_API_URL;
56-
this.apiKey = etherscanConfig.apiKey;
5756
this.#dispatcher = etherscanConfig.dispatcher;
5857
this.#pollingIntervalMs =
5958
etherscanConfig.dispatcher !== undefined
6059
? 0
6160
: VERIFICATION_STATUS_POLLING_SECONDS;
61+
62+
if (etherscanConfig.apiKey === "") {
63+
throw new HardhatError(
64+
HardhatError.ERRORS.HARDHAT_VERIFY.GENERAL.EXPLORER_API_KEY_EMPTY,
65+
{
66+
verificationProvider: this.name,
67+
},
68+
);
69+
}
70+
this.apiKey = etherscanConfig.apiKey;
6271
}
6372

6473
public getContractUrl(address: string) {

v-next/hardhat-verify/src/internal/hook-handlers/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function resolveUserConfig(
7272

7373
function resolveBlockscoutConfig(
7474
blockscoutConfig: BlockscoutUserConfig | undefined = {
75-
enabled: false,
75+
enabled: true,
7676
},
7777
): BlockscoutConfig {
7878
return {
@@ -83,7 +83,7 @@ function resolveBlockscoutConfig(
8383
function resolveEtherscanConfig(
8484
etherscanConfig: EtherscanUserConfig | undefined = {
8585
apiKey: "",
86-
enabled: false,
86+
enabled: true,
8787
},
8888
resolveConfigurationVariable: ConfigurationVariableResolver,
8989
): EtherscanConfig {

v-next/hardhat-verify/test/etherscan.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import querystring from "node:querystring";
33
import { beforeEach, describe, it } from "node:test";
44

55
import { HardhatError } from "@nomicfoundation/hardhat-errors";
6-
import { assertRejectsWithHardhatError } from "@nomicfoundation/hardhat-test-utils";
6+
import {
7+
assertRejectsWithHardhatError,
8+
assertThrowsHardhatError,
9+
} from "@nomicfoundation/hardhat-test-utils";
710

811
import { Etherscan, ETHERSCAN_API_URL } from "../src/internal/etherscan.js";
912

@@ -44,6 +47,20 @@ describe("etherscan", () => {
4447

4548
assert.equal(etherscan.name, "Etherscan");
4649
});
50+
51+
it("should throw an error if the apiKey is empty", () => {
52+
assertThrowsHardhatError(
53+
() =>
54+
new Etherscan({
55+
...etherscanConfig,
56+
apiKey: "",
57+
}),
58+
HardhatError.ERRORS.HARDHAT_VERIFY.GENERAL.EXPLORER_API_KEY_EMPTY,
59+
{
60+
verificationProvider: etherscanConfig.name,
61+
},
62+
);
63+
});
4764
});
4865

4966
describe("getContractUrl", () => {

v-next/hardhat-verify/test/hook-handlers/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ describe("hook-handlers/config", () => {
264264

265265
assert.deepEqual(resolvedConfig.verify, {
266266
blockscout: {
267-
enabled: false,
267+
enabled: true,
268268
},
269269
etherscan: {
270270
apiKey: new MockResolvedConfigurationVariable(""),
271-
enabled: false,
271+
enabled: true,
272272
},
273273
});
274274
});

0 commit comments

Comments
 (0)