6
6
7
7
## What
8
8
9
- This plugin helps you verify the source code for your Solidity contracts. At the moment, it supports [ Etherscan] ( https://etherscan.io ) -based explorers and explorers compatible with its API like [ Blockscout] ( https://www.blockscout.com/ ) .
9
+ This plugin helps you verify the source code for your Solidity contracts. At the moment, it supports [ Etherscan] ( https://etherscan.io ) -based explorers, explorers compatible with its API like [ Blockscout] ( https://www.blockscout.com/ ) and [ Sourcify ] ( https://sourcify.dev /) .
10
10
11
11
It's smart and it tries to do as much as possible to facilitate the process:
12
12
@@ -35,15 +35,15 @@ import "@nomicfoundation/hardhat-verify";
35
35
36
36
## Tasks
37
37
38
- This plugin provides the ` verify ` task, which allows you to verify contracts through Etherscan's service.
38
+ This plugin provides the ` verify ` task, which allows you to verify contracts through Sourcify and Etherscan's service.
39
39
40
40
## Environment extensions
41
41
42
42
This plugin does not extend the environment.
43
43
44
44
## Usage
45
45
46
- You need to add the following Etherscan config to your ` hardhat.config.js ` file:
46
+ You need to add the following Etherscan and Sourcify configs to your ` hardhat.config.js ` file:
47
47
48
48
``` js
49
49
module .exports = {
@@ -54,6 +54,11 @@ module.exports = {
54
54
// Your API key for Etherscan
55
55
// Obtain one at https://etherscan.io/
56
56
apiKey: " YOUR_ETHERSCAN_API_KEY"
57
+ },
58
+ sourcify: {
59
+ // Disabled by default
60
+ // Doesn't need an API key
61
+ enabled: true
57
62
}
58
63
};
59
64
```
@@ -234,44 +239,68 @@ hre.run("verify:verify", {
234
239
}
235
240
` ` `
236
241
237
- #### Advanced Usage: Using the Etherscan class from another plugin
242
+ #### Advanced Usage: Using the Etherscan and Sourcify classes from another plugin
238
243
239
- The Etherscan class used for contract verification can be imported from the plugin, allowing its direct usage:
244
+ Both Etherscan and Sourcify classes can be imported from the plugin for direct use.
240
245
241
- ` ` ` js
242
- import { Etherscan } from " @nomicfoundation/hardhat-verify/etherscan" ;
243
-
244
- const instance = new Etherscan (
245
- " abc123def123" , // Etherscan API key
246
- " https://api.etherscan.io/api" , // Etherscan API URL
247
- " https://etherscan.io" // Etherscan browser URL
248
- );
249
-
250
- if (! instance .isVerified (" 0x123abc..." )) {
251
- const { message: guid } = await instance .verify (
252
- // Contract address
253
- " 0x123abc..." ,
254
- // Contract source code
255
- ' {"language":"Solidity","sources":{"contracts/Sample.sol":{"content":"// SPDX-Lic..."}},"settings":{ ... }}' ,
256
- // Contract name
257
- " contracts/Sample.sol:MyContract" ,
258
- // Compiler version
259
- " v0.8.19+commit.7dd6d404" ,
260
- // Encoded constructor arguments
261
- " 0000000000000000000000000000000000000000000000000000000000000032"
262
- );
246
+ - **Etherscan Class Usage**
263
247
264
- await sleep ( 1000 );
265
- const verificationStatus = await instance . getVerificationStatus (guid) ;
248
+ ` ` ` js
249
+ import { Etherscan } from " @nomicfoundation/hardhat-verify/etherscan " ;
266
250
267
- if (verificationStatus .isSuccess ()) {
268
- const contractURL = instance .getContractUrl (" 0x123abc..." );
269
- console .log (
270
- ` Successfully verified contract "MyContract" on Etherscan: ${ contractURL} `
251
+ const instance = new Etherscan (
252
+ " abc123def123" , // Etherscan API key
253
+ " https://api.etherscan.io/api" , // Etherscan API URL
254
+ " https://etherscan.io" // Etherscan browser URL
255
+ );
256
+
257
+ if (! instance .isVerified (" 0x123abc..." )) {
258
+ const { message: guid } = await instance .verify (
259
+ // Contract address
260
+ " 0x123abc..." ,
261
+ // Contract source code
262
+ ' {"language":"Solidity","sources":{"contracts/Sample.sol":{"content":"// SPDX-Lic..."}},"settings":{ ... }}' ,
263
+ // Contract name
264
+ " contracts/Sample.sol:MyContract" ,
265
+ // Compiler version
266
+ " v0.8.19+commit.7dd6d404" ,
267
+ // Encoded constructor arguments
268
+ " 0000000000000000000000000000000000000000000000000000000000000032"
271
269
);
270
+
271
+ await sleep (1000 );
272
+ const verificationStatus = await instance .getVerificationStatus (guid);
273
+
274
+ if (verificationStatus .isSuccess ()) {
275
+ const contractURL = instance .getContractUrl (" 0x123abc..." );
276
+ console .log (
277
+ ` Successfully verified contract "MyContract" on Etherscan: ${ contractURL} `
278
+ );
279
+ }
272
280
}
273
- }
274
- ` ` `
281
+ ` ` `
282
+
283
+ - **Sourcify Class Usage**
284
+
285
+ ` ` ` js
286
+ import { Sourcify } from " @nomicfoundation/hardhat-verify/sourcify" ;
287
+
288
+ const instance = new Sourcify (1 ); // Set chainId
289
+
290
+ if (! instance .isVerified (" 0x123abc..." )) {
291
+ const sourcifyResponse = await instance .verify (" 0x123abc..." , {
292
+ " metadata.json" : " {...}" ,
293
+ " otherFile.sol" : " ..." ,
294
+ });
295
+ if (sourcifyResponse .isOk ()) {
296
+ const contractURL = instance .getContractUrl (
297
+ " 0x123abc..." ,
298
+ sourcifyResponse .status
299
+ );
300
+ console .log (` Successfully verified contract on Sourcify: ${ contractURL} ` );
301
+ }
302
+ }
303
+ ` ` `
275
304
276
305
## How it works
277
306
0 commit comments