How to Verify Contracts
Vyper contracts are verifiable only using the dedicated /verify/vyper API enpoint. UI, frameworks and tools don't support Vyper verification via Sourcify yet.
Using the UI (legacy)
- Drag and drop the folder containing your source files and metadata, or add them seperately.
- Input the contract address you want to verify.
- Select the chain the contract is deployed to.
- Click "Verify".
Foundry
Foundry natively supports Sourcify verification. You can verify contracts with the additional verify flags in Forge:
Deploy and verify a contract:
forge create --rpc-url <your_rpc_url> \
--constructor-args "ForgeUSD" "FUSD" 18 1000000000000000000000 \
--private-key <your_private_key> \
src/MyToken.sol:MyToken \
--verify \
--verification-provider sourcify
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
Verify an already deployed (and compiled) contract
forge verify-contract 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
src/MyToken.sol:MyToken \
--chain-id 11155111 \
--verifier sourcify
--verifier-url https://localhost:5555 # optional, defaults to https://sourcify.dev/server/
Check if a contract is verified
forge verify-check 0x55f7d4279CE387067f12561e7E0c194f5186cFba \
--chain-id 11155111 \
--verifier sourcify
Hardhat
hardhat-verify plugin
The Hardhat plugin @nomicfoundation/hardhat-verify has official Sourcify support.
In order to enable Sourcify support, add this to hardhat.config.js
:
sourcify: {
enabled: true,
// Optional: specify a different Sourcify server
apiUrl: "https://sourcify.dev/server",
// Optional: specify a different Sourcify repository
browserUrl: "https://repo.sourcify.dev",
}
After deploying your contracts you can verify on Sourcify with:
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS
With Hardhat output
Sourcify can parse the Hardhat .json
output file under artifacts/build-info
to verify contracts.
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
- Drag and drop the
.json
file at sourcify.dev. - Select the main contract deployed at the address you want to verify.
- Input the address and chain and click "Verify".
Truffle
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.
truffle-verify-plugin
If you've deployed your contracts with Truffle, you can use the truffle-plugin-verify to verify contracts on Sourcify. The plugin verifies on Sourcify by default.
$ truffle run verify MyFirstContract MySecondContract --network goerli
Remix Plugin
Remix has a plugin to aid with contract verification and lookup. Please click this link to activate the plugin in Remix: https://remix.ethereum.org/?#activate=contract-verification
Verifying
To verify:
- Select the contract you want to verify in the file explorer
- Compile the contract
- Click on the Contract Verification icon on the left sidebar
- Enter the chain and the address of the contract you want to verify
- Select the contract you just compiled
- Make sure Sourcify is selected
- Click on Verify
Fetching
You can also check if contracts are verified on Sourcify and download their source code into your Remix IDE. To fetch:
- Click on the Contract Verification icon on the left sidebar
- Select "Lookup" on the top of the plugin view
- Enter the chain and the address of the contract you want to fetch
- Click on "Open in Remix" below the Sourcify status
The contract files will be saved in the file explorer.
Other Sourcify wrappers and tools
Do you have a tool to be listed? Let us know!