Skip to main content

How to Verify Contracts

Available only forSolidity

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)

  1. Drag and drop the folder containing your source files and metadata, or add them seperately.
  2. Input the contract address you want to verify.
  3. Select the chain the contract is deployed to.
  4. 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.

info

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

  1. Drag and drop the .json file at sourcify.dev.
  2. Select the main contract deployed at the address you want to verify.
  3. 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:

  1. Select the contract you want to verify in the file explorer
  2. Compile the contract
  3. Click on the Contract Verification icon on the left sidebar
  4. Enter the chain and the address of the contract you want to verify
  5. Select the contract you just compiled
  6. Make sure Sourcify is selected
  7. 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:

  1. Click on the Contract Verification icon on the left sidebar
  2. Select "Lookup" on the top of the plugin view
  3. Enter the chain and the address of the contract you want to fetch
  4. 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!