Skip to content

Commit 6caf1db

Browse files
committed
Update "How to Verify" docs
1 parent 8f5160d commit 6caf1db

File tree

12 files changed

+103
-89
lines changed

12 files changed

+103
-89
lines changed

docs/3. Verification/1.howToVerify.mdx

Lines changed: 100 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,98 @@ title: How to Verify Contracts
44
slug: /how-to-verify
55
---
66

7-
import AvailableOnlyForSolidityAdmonition from "../AvailableOnlyForSolidityAdmonition";
7+
import chainAddress from "./chain-address.png"
8+
import verificationMethods from "./methods.png"
9+
import importSources from "./import-sources.png"
10+
import jobError from "./job-error.png"
11+
import bytecodeDiff from "./bytecode-diff.png"
812

913
# How to Verify Contracts
1014

11-
<AvailableOnlyForSolidityAdmonition description="Vyper contracts are verifiable only using the dedicated /verify/vyper API enpoint. UI, frameworks and tools don't support Vyper verification via Sourcify yet."/>
15+
There are multiple ways to verify a contract on Sourcify. Depending on your use case, you can choose the best way.
1216

13-
## Using the UI (legacy)
17+
Some of these methods are using the legacy Sourcify API. This will be deprecated in the near future. Use Sourcify APIv2 instead (see [APIv2 docs](/docs/api)).
1418

15-
1. Drag and drop the folder containing your source files and metadata, or add them seperately.
16-
2. Input the contract address you want to verify.
17-
3. Select the chain the contract is deployed to.
18-
4. Click "Verify".
19+
With APIv2 when you submit a verification, this will create a verification job. You can then check the status of the job and get the verification result. See one example in the UI [here](https://verify.sourcify.dev/jobs/f4ed8a9b-c852-4ac6-ac99-bd71ffb01305).
1920

20-
<div>
21-
<video width="100%" height="100%" playsinline autoplay muted controls>
22-
<source src="/videos/simple-verify.mp4" type="video/mp4" />
23-
</video>
21+
## UI
22+
23+
You can verify using our new verification UI at https://verify.sourcify.dev. See the Github repo [here](https://github.com/sourcifyeth/verify.sourcify.dev).
24+
25+
First choose the chain you want to verify the contract on and provide the contract address.
26+
<div style={{display: "flex", flexDirection: "row", gap: "10px", justifyContent: "center"}}>
27+
<img src={chainAddress} alt="Chain and address" style={{width: "100%", maxWidth: "600px"}} />
28+
</div>
29+
30+
This will automatically check if the contract is verified on Sourcify on the same chain and all other supported chains.
31+
32+
### Importing a contract
33+
34+
You can import a verified contract from different sources:
35+
36+
- **Etherscan**: Enter the chain and contract address to import the contract. You need an Etherscan API key to use this feature. Open the "Settings" on top right to add your API key. API keys are used locally in the browser and are not sent to Sourcify servers.
37+
<div style={{display: "flex", flexDirection: "row", gap: "10px", justifyContent: "center"}}>
38+
<img src={importSources} alt="Import sources" style={{width: "100%", maxWidth: "600px"}} />
2439
</div>
2540

26-
## Foundry
41+
### Verification Methods
42+
43+
For both Solidity and Vyper contracts you can choose between the following verification methods:
44+
45+
- **Single file**: Provide single .sol or .vy file, alongside compiler settings.
46+
- **Multiple files**: Provide multiple .sol or .vy files, alongside compiler settings.
47+
- (preferred) **Standard JSON**: Provide a [standard JSON input file](https://docs.soliditylang.org/en/v0.8.30/using-the-compiler.html#input-description).
48+
49+
Prefer using the standard JSON or framework commands directly (see below) to maintain the full compilation and avoid any changes. Different compiler settings can break the verification. Flattening the sources also breaks the metadata hashes and you won't be able to get an ["Exact Match"](/docs/exact-match-vs-match).
50+
51+
Additionally the following option is available for Solidity contracts:
52+
- **Metadata.json**: Provide a [metadata.json file](/docs/metadata) to verify the contract in the first file input field. Provide all the source files in the second file input field. This option checks the source hashes in the metadata.json provided and compares them with the hashes of the source files provided before submitting the verification.
53+
54+
<div style={{display: "flex", flexDirection: "column", gap: "10px", alignItems: "center"}}>
55+
<img src={verificationMethods} alt="Verification methods" style={{width: "100%", maxWidth: "600px"}} />
56+
<div style={{fontSize: "12px", color: "gray", fontStyle: "italic"}}>Available verification methods</div>
57+
</div>
2758

28-
Foundry natively supports Sourcify verification. You can verify contracts with the additional verify flags in Forge:
59+
### Contract Identifier
2960

30-
Deploy and verify a contract:
61+
From the files and contracts provided, we will ask you to select the contract you want to verify. Ie. if you've written a contract called `MyContract.sol` using other contracts `Ownable.sol` and `ERC20.sol`, you will be asked to select `MyContract.sol` as the contract to verify.
3162

63+
The format of the contract identifier is path:contractName e.g.
3264
```
65+
path/to/contractName.sol:contractName
66+
```
67+
68+
The verification UI will parse the files and give you a list of contracts to choose from. You can always input the contract identifier manually.
69+
70+
### (Optional) Creation Transaction Hash
71+
72+
Sourcify needs to find the transaction the contract was deployed in to get the creation bytecode. We get this information from different sources like block explorers (see [here](https://github.com/ethereum/sourcify/blob/staging/services/server/src/sourcify-chains-default.json)). You can still provide a creation transaction hash manually if you want to, or if Sourcify fails to verify via creation bytecode.
73+
74+
## Verification Job
75+
76+
Once you've provided all the information, you can submit the verification. This will create a verification job. You can see the job in the UI and get the verification result.
77+
78+
If the verification fails you can see the error message and why it failed.
79+
80+
<div style={{display: "flex", flexDirection: "column", gap: "10px", alignItems: "center"}}>
81+
<img src={jobError} alt="Job error" style={{width: "100%", maxWidth: "600px"}} />
82+
<div style={{fontSize: "12px", color: "gray", fontStyle: "italic"}}>Example of a verification job that failed</div>
83+
</div>
84+
85+
You can see the diffs of the bytecodes if the compilation succeeds but the bytecodes did not match.
86+
87+
<div style={{display: "flex", flexDirection: "column", gap: "10px", alignItems: "center"}}>
88+
<img src={bytecodeDiff} alt="Bytecode diff" style={{width: "100%", maxWidth: "600px"}} />
89+
<div style={{fontSize: "12px", color: "gray", fontStyle: "italic"}}>Bytecode diffs</div>
90+
</div>
91+
92+
## Foundry (legacy API)
93+
94+
Foundry natively supports Sourcify verification. You can verify contracts with the additional verify flags in Forge.
95+
96+
(This is still using the legacy Sourcify API)
97+
98+
```bash title="Deploy and verify a contract"
3399
forge create --rpc-url <your_rpc_url> \
34100
--constructor-args "ForgeUSD" "FUSD" 18 1000000000000000000000 \
35101
--private-key <your_private_key> \
@@ -39,33 +105,31 @@ forge create --rpc-url <your_rpc_url> \
39105
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
40106
```
41107

42-
Verify an already deployed (and compiled) contract
43-
44-
```
108+
```bash title="Verify an already deployed (and compiled) contract"
45109
forge verify-contract 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
46110
src/MyToken.sol:MyToken \
47111
--chain-id 11155111 \
48112
--verifier sourcify
49113
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
50114
```
51115

52-
Check if a contract is verified
53-
54-
```
116+
```bash title="Check if a contract is verified"
55117
forge verify-check 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
56118
--chain-id 11155111 \
57119
--verifier sourcify
58120
```
59121

60-
## Hardhat
122+
## Hardhat (legacy API)
61123

62124
### hardhat-verify plugin
63125

64-
The Hardhat plugin [@nomicfoundation/hardhat-verify](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) has official Sourcify support.
126+
The Hardhat plugin [@nomicfoundation/hardhat-verify](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) has official Sourcify support.
127+
128+
(This is still using the legacy Sourcify API)
65129

66130
In order to enable Sourcify support, add this to `hardhat.config.js`:
67131

68-
```
132+
```js title="hardhat.config.js"
69133
sourcify: {
70134
enabled: true,
71135
// Optional: specify a different Sourcify server
@@ -77,80 +141,30 @@ sourcify: {
77141

78142
After deploying your contracts you can verify on Sourcify with:
79143

80-
```
144+
```bash title="Verify a contract"
81145
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS
82146
```
83147

84-
### With Hardhat output
85-
86-
Sourcify can parse the Hardhat `.json` output file under `artifacts/build-info` to verify contracts.
87-
88-
:::info
89-
Only after Hardhat version v2.6.8 the metadata files were output by default. If you are using an earlier version, you need to add the metadata to compilation outputs manually as [described here](/docs/metadata/#hardhat---earlier-than-v268)
90-
:::
91-
92-
1. Drag and drop the `.json` file at [sourcify.dev](https://sourcify.dev).
93-
2. Select the main contract deployed at the address you want to verify.
94-
3. Input the address and chain and click "Verify".
95-
96-
<div>
97-
<video width="100%" height="100%" playsinline autoplay muted controls>
98-
<source src="/videos/hardhat-sourcify.mp4" type="video/mp4" />
99-
</video>
100-
</div>
101-
102-
## Truffle
103-
104-
If you were using Truffle to compile contracts, you can use the output file at `build/contracts/<contract-name>.json` for the metadata file. Then add the source files as usual.
105-
106-
### truffle-verify-plugin
107-
108-
If you've deployed your contracts with Truffle, you can use the [truffle-plugin-verify](https://github.com/rkalis/truffle-plugin-verify) to verify contracts on Sourcify. The plugin verifies on Sourcify by default.
109-
110-
```bash
111-
$ truffle run verify MyFirstContract MySecondContract --network goerli
112-
```
113-
114-
## Remix Plugin
115-
116-
Remix has a plugin to aid with contract verification and lookup.
117-
Please click this link to activate the plugin in Remix: [https://remix.ethereum.org/?#activate=contract-verification](https://remix.ethereum.org/?#activate=contract-verification)
118-
119-
### Verifying
148+
## Remix
120149

121-
To verify:
150+
You can use the "unified verification plugin" written by the Sourcify team to verify on multiple verifiers on Remix.
122151

123-
1. Select the contract you want to verify in the file explorer
124-
2. Compile the contract
125-
3. Click on the Contract Verification icon on the left sidebar
126-
4. Enter the chain and the address of the contract you want to verify
127-
5. Select the contract you just compiled
128-
6. Make sure Sourcify is selected
129-
7. Click on Verify
152+
1. Click on the "Plugins" tab in bottom of the sidebar and search for "Contract Verification"
153+
2. Enable the plugin "Contract Verification"
154+
3. Click on the "Contract Verification" tab in the sidebar
155+
5. Enter the contract address and select a chain
156+
6. Select the contract to verify (you need to have compiled a contract on Remix first)
157+
7. By default all verifiers are enabled. For Etherscan you need to add your API key in the "Settings" tab
158+
8. You can see the verification result in the "Receipts" tab
130159

131160
<div>
132161
<video width="100%" height="100%" playsinline autoplay muted controls>
133-
<source src="/videos/remix-verify.mp4" type="video/mp4" />
162+
<source src="/videos/remix.mp4" type="video/mp4" />
134163
</video>
135164
</div>
165+
## API
136166

137-
### Fetching
138-
139-
You can also check if contracts are verified on Sourcify and download their source code into your Remix IDE.
140-
To fetch:
141-
142-
1. Click on the Contract Verification icon on the left sidebar
143-
2. Select "Lookup" on the top of the plugin view
144-
3. Enter the chain and the address of the contract you want to fetch
145-
4. Click on "Open in Remix" below the Sourcify status
146-
147-
The contract files will be saved in the file explorer.
148-
149-
<div>
150-
<video width="100%" height="100%" playsinline autoplay muted controls>
151-
<source src="/videos/remix-lookup.mp4" type="video/mp4" />
152-
</video>
153-
</div>
167+
See the [API docs](/docs/api) for more information.
154168

155169
## Other Sourcify wrappers and tools
156170

352 KB
Loading
123 KB
Loading
58.8 KB
Loading

docs/3. Verification/job-error.png

116 KB
Loading

docs/3. Verification/methods.png

97.1 KB
Loading

docusaurus.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const config = {
6363
{
6464
to: "/docs/exact-match-vs-match",
6565
from: "/docs/full-vs-partial-match",
66-
}
66+
},
6767
],
6868
},
6969
],
@@ -72,8 +72,7 @@ const config = {
7272
themeConfig:
7373
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
7474
({
75-
image:
76-
"https://raw.githubusercontent.com/sourcifyeth/assets/master/logo-assets-png/sourcify_blue_rounded.png",
75+
image: "https://raw.githubusercontent.com/sourcifyeth/assets/master/logo-assets-png/sourcify_blue_rounded.png",
7776
metadata: [
7877
{
7978
property: "og:title",
@@ -174,6 +173,7 @@ const config = {
174173
prism: {
175174
theme: lightCodeTheme,
176175
darkTheme: darkCodeTheme,
176+
additionalLanguages: ["solidity", "bash"],
177177
},
178178
algolia: {
179179
// The application ID provided by Algolia

static/videos/hardhat-sourcify.mp4

-456 KB
Binary file not shown.

static/videos/remix-lookup.mp4

-1.06 MB
Binary file not shown.

static/videos/remix-verify.mp4

-1.71 MB
Binary file not shown.

0 commit comments

Comments
 (0)