Skip to content

Commit 7772524

Browse files
authored
Merge pull request #4549 from sourcifyeth/main
add Sourcify example in "Advanced Usage" in readme
2 parents 6dc76a5 + 1b66262 commit 7772524

File tree

1 file changed

+64
-35
lines changed

1 file changed

+64
-35
lines changed

packages/hardhat-verify/README.md

+64-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## What
88

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/).
1010

1111
It's smart and it tries to do as much as possible to facilitate the process:
1212

@@ -35,15 +35,15 @@ import "@nomicfoundation/hardhat-verify";
3535

3636
## Tasks
3737

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.
3939

4040
## Environment extensions
4141

4242
This plugin does not extend the environment.
4343

4444
## Usage
4545

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:
4747

4848
```js
4949
module.exports = {
@@ -54,6 +54,11 @@ module.exports = {
5454
// Your API key for Etherscan
5555
// Obtain one at https://etherscan.io/
5656
apiKey: "YOUR_ETHERSCAN_API_KEY"
57+
},
58+
sourcify: {
59+
// Disabled by default
60+
// Doesn't need an API key
61+
enabled: true
5762
}
5863
};
5964
```
@@ -234,44 +239,68 @@ hre.run("verify:verify", {
234239
}
235240
```
236241
237-
#### Advanced Usage: Using the Etherscan class from another plugin
242+
#### Advanced Usage: Using the Etherscan and Sourcify classes from another plugin
238243
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.
240245
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**
263247
264-
await sleep(1000);
265-
const verificationStatus = await instance.getVerificationStatus(guid);
248+
```js
249+
import { Etherscan } from "@nomicfoundation/hardhat-verify/etherscan";
266250

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"
271269
);
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+
}
272280
}
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+
```
275304
276305
## How it works
277306

0 commit comments

Comments
 (0)