Skip to content

Commit dd7b392

Browse files
Update hardhat and foundry information (#57)
* Update Hardhat verification documentation for v3 * Update Foundry verification documentation to newest version * Reduce Solidity metadata Foundry and Hardhat sections to only describing where to find metadata * Add note about Etherscan getting default with api key * Reword Foundry support --------- Co-authored-by: Kaan Uzdoğan <kaanuzdogan@gmail.com>
1 parent 2052da5 commit dd7b392

3 files changed

Lines changed: 58 additions & 63 deletions

File tree

docs/5. Verify on Sourcify/4. Verify via Hardhat.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,55 @@ slug: /verify-via-hardhat
44
title: Verify via Hardhat
55
---
66

7-
The Hardhat plugin [@nomicfoundation/hardhat-verify](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) has official Sourcify support.
7+
:::info Hardhat v3
8+
This page covers **Hardhat v3**. For Hardhat v2, see the [hardhat-verify plugin docs](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify).
9+
:::
810

9-
Sourcify verification is enabled by default in recent plugin versions.
11+
The [`@nomicfoundation/hardhat-verify`](https://hardhat.org/docs/plugins/hardhat-verify) plugin has built-in Sourcify support. No configuration is needed — Sourcify verification runs automatically when you run `hardhat verify`.
1012

11-
You only need explicit config if you want to set custom endpoints (for example when using your own Sourcify instance):
13+
## Setup
1214

13-
```js title="hardhat.config.js"
14-
sourcify: {
15-
enabled: true, // Optional, true by default
16-
// Optional: specify a different Sourcify server
17-
apiUrl: "https://sourcify.dev/server",
18-
// Optional: specify a different Sourcify repository
19-
browserUrl: "https://repo.sourcify.dev",
20-
}
15+
The plugin comes pre-installed in Hardhat v3 template projects. To add it manually:
16+
17+
```bash
18+
npm install --save-dev @nomicfoundation/hardhat-verify
19+
```
20+
21+
```typescript title="hardhat.config.ts"
22+
import { defineConfig } from "hardhat/config";
23+
import hardhatVerify from "@nomicfoundation/hardhat-verify";
24+
25+
export default defineConfig({
26+
plugins: [hardhatVerify],
27+
});
2128
```
2229

23-
After deploying your contracts you can verify on Sourcify with:
30+
## Verification
31+
32+
After deploying, verify on all services (Etherscan, Blockscout, Sourcify) with:
2433

25-
```bash title="Verify a contract"
34+
```bash
2635
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS
2736
```
2837

29-
The Hardhat plugin currently uses Sourcify's legacy verification endpoints internally. The `/v2` and `/v3` API endpoints documented elsewhere apply to direct API integrations, not to this Hardhat command.
38+
To verify on Sourcify only:
39+
40+
```bash
41+
npx hardhat verify sourcify --network mainnet DEPLOYED_CONTRACT_ADDRESS
42+
```
43+
44+
## Custom Sourcify instance
45+
46+
If you're running your own Sourcify instance, configure the endpoints under `verify`:
47+
48+
```typescript title="hardhat.config.ts"
49+
export default defineConfig({
50+
plugins: [hardhatVerify],
51+
verify: {
52+
sourcify: {
53+
// Specify a different Sourcify server here
54+
apiUrl: "https://sourcify.dev/server",
55+
},
56+
},
57+
});
58+
```

docs/5. Verify on Sourcify/5. Verify via Foundry.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@ slug: /verify-via-foundry
44
title: Verify via Foundry
55
---
66

7-
Foundry natively supports Sourcify verification. You can verify contracts with the additional verify flags in Forge.
7+
Foundry natively supports Sourcify verification. Sourcify is the **default verifier** in Forge if you don't add an Etherscan API key. If you added a key you should set the verifier explicitly `--verifier sourcify`.
88

9-
(This is still using the legacy Sourcify API)
9+
## Deploy and verify
1010

11-
```bash title="Deploy and verify a contract"
11+
```bash
1212
forge create --rpc-url <your_rpc_url> \
1313
--constructor-args "ForgeUSD" "FUSD" 18 1000000000000000000000 \
1414
--private-key <your_private_key> \
1515
src/MyToken.sol:MyToken \
1616
--verify \
17-
--verification-provider sourcify
18-
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
17+
--verifier sourcify
1918
```
2019

21-
```bash title="Verify an already deployed (and compiled) contract"
20+
## Verify an existing contract
21+
22+
```bash
2223
forge verify-contract 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
2324
src/MyToken.sol:MyToken \
24-
--chain-id 11155111 \
25+
--chain 11155111 \
2526
--verifier sourcify
26-
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
2727
```
2828

29-
```bash title="Check if a contract is verified"
30-
forge verify-check 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
31-
--chain-id 11155111 \
29+
## Check verification job status
30+
31+
```bash
32+
forge verify-check 64f6f3bb-2b93-40ec-b6e8-b6e90510e6b0 \
3233
--verifier sourcify
3334
```

docs/6. Sourcify in depth/2. Solidity metadata.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,47 +54,12 @@ To have the metadata in the ouput of the compilation with Solidity's [standard J
5454

5555
### Foundry
5656

57-
Foundry stores the contract compilation outputs to `out/CONTRACT_NAME` folder. The `.json` file contains the metadata of the contract under `"rawMetadata"` and `"metadata"` fields. However you don't need to extract the metadata manually for verification.
57+
Foundry stores the contract compilation outputs to `out/CONTRACT_NAME` folder. The `.json` file contains the metadata of the contract under `"rawMetadata"` and `"metadata"` fields.
5858

5959
You can use the `forge verify-contract` command to verify a contract. See [Foundry verification](/docs/verify-via-foundry) for more details.
6060

61-
Simply drag and drop the output `.json` file of the contract you want to verify to the [sourcify.dev](https://sourcify.dev) UI or provide it as the metadata file to the [API](/docs/api).
62-
6361
### Hardhat
6462

65-
You can use the native Hardhat [verify plugin](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) to verify your contracts. See [Hardhat verification](/docs/verify-via-hardhat) for more details.
66-
67-
Hardhat stores the outputs of the compilations under the `artifacts/build-info/` folder inside the project. The `.json` file under the folder contains the [Standard JSON Input-Output](https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description) of the Solidity compiler for all contracts.
68-
69-
Since [v2.6.8](https://github.com/nomiclabs/hardhat/releases/tag/hardhat%402.6.8), Hardhat outputs the metadata files of each contract by default under the JSON's `.output.contracts.<contract-path>.<contract-name>.metadata` field. You don't have to extract the metadata manually. To verify via the Hardhat output you can provide the JSON containing the artifacts to Sourcify via UI or API. See [Hardhat verification](/docs/verify-via-hardhat) for more details. If the file is too large, try zippping it and uploading the zip file.
70-
71-
### Hardhat - earlier than v2.6.8
72-
73-
If you use an earlier version of Hardhat than 2.6.8 you can modify the `hardhat-config.js` manually to output metadata inside the `build-info/` file:
74-
75-
```js
76-
// hardat-config.js
77-
module.exports = {
78-
...
79-
solidity: {
80-
settings: {
81-
version: ...,
82-
optimizer: {...},
83-
outputSelection: {
84-
"*": {
85-
"*": [
86-
"abi",
87-
"evm.bytecode",
88-
"evm.deployedBytecode",
89-
"metadata", // <-- add this
90-
...
91-
]
92-
},
93-
},
94-
},
95-
},
96-
...
97-
};
98-
```
63+
Hardhat stores the outputs of the compilations under the `artifacts/build-info/` folder inside the project. The `.json` files under the folder contain the [Standard JSON Output](https://docs.soliditylang.org/en/latest/using-the-compiler.html#output-description) of the Solidity compiler for all contracts. Hardhat outputs the metadata files of each contract by default under the JSON's `output.contracts.<contract-path>.<contract-name>.metadata` field.
9964

100-
In theory, if you haven't changed any of the compilation settings, it should result in the same metadata file and you should get an exact match. Otherwise you will be able to get a match only.
65+
You can use the native Hardhat [verify plugin](https://hardhat.org/docs/plugins/hardhat-verify) to verify your contracts. See [Hardhat verification](/docs/verify-via-hardhat) for more details.

0 commit comments

Comments
 (0)