Skip to content

Commit 377796b

Browse files
authored
Merge pull request #4693 from NomicFoundation/sourcify-options
hardhat-verify: add apiUrl and browserUrl in sourcify options
2 parents 4f075aa + 1976417 commit 377796b

File tree

8 files changed

+42
-7
lines changed

8 files changed

+42
-7
lines changed

.changeset/bright-plums-watch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/hardhat-verify": patch
3+
---
4+
5+
Add apiUrl and browserUrl to Sourcify configuration.

packages/hardhat-verify/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ To verify a contract using Sourcify, you need to add to your Hardhat config:
186186
```js
187187
sourcify: {
188188
enabled: true,
189+
// Optional: specify a different Sourcify server
190+
apiUrl: "https://sourcify.dev/server",
191+
// Optional: specify a different Sourcify repository
192+
browserUrl: "https://repo.sourcify.dev",
189193
}
190194
```
191195

@@ -285,7 +289,11 @@ Both Etherscan and Sourcify classes can be imported from the plugin for direct u
285289
```js
286290
import { Sourcify } from "@nomicfoundation/hardhat-verify/sourcify";
287291

288-
const instance = new Sourcify(1); // Set chainId
292+
const instance = new Sourcify(
293+
1,
294+
"https://sourcify.dev/server",
295+
"https://repo.sourcify.dev"
296+
); // Set chainId
289297

290298
if (!instance.isVerified("0x123abc...")) {
291299
const sourcifyResponse = await instance.verify("0x123abc...", {

packages/hardhat-verify/src/internal/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export function sourcifyConfigExtender(
3737
): void {
3838
const defaultSourcifyConfig: SourcifyConfig = {
3939
enabled: false,
40+
apiUrl: "https://sourcify.dev/server",
41+
browserUrl: "https://repo.sourcify.dev",
4042
};
4143
const cloneDeep = require("lodash.clonedeep") as typeof LodashCloneDeepT;
4244
const userSourcifyConfig = cloneDeep(userConfig.sourcify);

packages/hardhat-verify/src/internal/sourcify.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import { ContractStatus } from "./sourcify.types";
1212
import { ValidationResponse } from "./utilities";
1313

1414
export class Sourcify {
15-
public apiUrl: string = "https://sourcify.dev/server";
16-
public browserUrl: string = "https://repo.sourcify.dev";
17-
18-
constructor(public chainId: number) {}
15+
constructor(
16+
public chainId: number,
17+
public apiUrl: string,
18+
public browserUrl: string
19+
) {}
1920

2021
// https://sourcify.dev/server/api-docs/#/Repository/get_check_all_by_addresses
2122
public async isVerified(address: string) {

packages/hardhat-verify/src/internal/tasks/sourcify.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CompilerVersionsMismatchError,
1515
ContractVerificationFailedError,
1616
HardhatNetworkNotSupportedError,
17+
HardhatVerifyError,
1718
InvalidAddressError,
1819
InvalidContractNameError,
1920
MissingAddressError,
@@ -67,7 +68,17 @@ subtask(TASK_VERIFY_SOURCIFY)
6768
16
6869
);
6970

70-
const sourcify = new Sourcify(currentChainId);
71+
const { apiUrl, browserUrl } = config.sourcify;
72+
73+
if (apiUrl === undefined) {
74+
throw new HardhatVerifyError("Sourcify `apiUrl` is not defined");
75+
}
76+
77+
if (browserUrl === undefined) {
78+
throw new HardhatVerifyError("Sourcify `browserUrl` is not defined");
79+
}
80+
81+
const sourcify = new Sourcify(currentChainId, apiUrl, browserUrl);
7182

7283
const status = await sourcify.isVerified(address);
7384
if (status !== false) {

packages/hardhat-verify/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface EtherscanConfig {
1515

1616
export interface SourcifyConfig {
1717
enabled: boolean;
18+
apiUrl?: string;
19+
browserUrl?: string;
1820
}
1921

2022
export type ApiKey = string | Record<string, string>;

packages/hardhat-verify/test/unit/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ describe("Extend config", () => {
168168
const userConfig: HardhatUserConfig = {};
169169
const expected: SourcifyConfig = {
170170
enabled: false,
171+
apiUrl: "https://sourcify.dev/server",
172+
browserUrl: "https://repo.sourcify.dev",
171173
};
172174
sourcifyConfigExtender(hardhatConfig, userConfig);
173175

packages/hardhat-verify/test/unit/sourcify.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ describe("Sourcify", () => {
99
it("should return the contract url", () => {
1010
const expectedContractAddress =
1111
"https://repo.sourcify.dev/contracts/full_match/100/0xC4c622862a8F548997699bE24EA4bc504e5cA865/";
12-
const sourcify = new Sourcify(chainId);
12+
const sourcify = new Sourcify(
13+
chainId,
14+
"https://sourcify.dev/server",
15+
"https://repo.sourcify.dev"
16+
);
1317
const contractUrl = sourcify.getContractUrl(
1418
"0xC4c622862a8F548997699bE24EA4bc504e5cA865",
1519
ContractStatus.PERFECT

0 commit comments

Comments
 (0)