How to Verify Contracts
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
Sourcify has a remix plugin to aid with contract verification and lookup. The plugin can be found in this repository https://github.com/sourcifyeth/remix-sourcify
Verifying
To verify:
- Select the contract you want to verify in the file explorer
- Compile the contract
- Click on the Sourcify icon on the plugin manager
- Enter the chain and the address of the contract you want to verify
- Click on Verify
Fetching
You can also "fetch" contracts that are verified on Sourcify into your Remix IDE. To fetch:
- Click on the Sourcify icon on the plugin manager
- Enter the chain and the address of the contract you want to fetch
- Click on Fetch
The contract files will be saved in the file explorer.
Installation
- Navigate to the Remix Plugin manager
- Search for
Sourcify
and click on Activate when you see it. - Another option would be to click on the Sourcify logo on Remix Homepage to activate the plugin
Other Sourcify wrappers and tools
Do you have a tool to be listed? Let us know!