For the complete documentation index, see llms.txt. This page is also available as Markdown.

Verify using Hardhat

Learn how to verify smart contracts on the Filecoin network using Hardhat with various verification services including Blockscout, Sourcify, and Filfox.

This guide shows you how to verify your smart contracts using Hardhat on the Filecoin network.

Prerequisites

  • A Hardhat project set up for Filecoin development. If you don't have one, start with the FEVM Hardhat Kit.

  • The @nomicfoundation/hardhat-verify plugin installed and imported in your Hardhat config.

  • A deployed contract address on Filecoin mainnet or Calibration testnet.

  • The same Solidity version, optimizer settings, and source tree that were used for deployment.

  • Contract constructor arguments, if the contract was deployed with any.

  • A Filecoin RPC URL for the target network. Filecoin mainnet uses chain ID 314; Calibration testnet uses chain ID 314159.

Verification Methods

Blockscout Verification

Blockscout is a popular blockchain explorer that supports contract verification. The FEVM Hardhat Kit already includes the Filecoin networks and verifier configuration. In another Hardhat v2 project, add equivalent configuration to hardhat.config.ts:

import "@nomicfoundation/hardhat-verify";
import { HardhatUserConfig } from "hardhat/config";

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.23",
    settings: {
      optimizer: {
        enabled: true,
        runs: 1000,
      },
    },
  },
  networks: {
    filecoin: {
      url: process.env.FILECOIN_RPC_URL ?? "https://api.node.glif.io/rpc/v1",
      chainId: 314,
    },
    calibration: {
      url: process.env.CALIBRATION_RPC_URL ?? "https://api.calibration.node.glif.io/rpc/v1",
      chainId: 314159,
    },
  },
  etherscan: {
    apiKey: {
      filecoin: "empty",
      calibration: "empty",
    },
    customChains: [
      {
        network: "filecoin",
        chainId: 314,
        urls: {
          apiURL: "https://filecoin.blockscout.com/api",
          browserURL: "https://filecoin.blockscout.com",
        },
      },
      {
        network: "calibration",
        chainId: 314159,
        urls: {
          apiURL: "https://filecoin-testnet.blockscout.com/api",
          browserURL: "https://filecoin-testnet.blockscout.com",
        },
      },
    ],
  }
};

export default config;

Set RPC URLs in your shell or .env if you do not want to use the example defaults:

Compile with the same settings used for deployment, then verify the deployed address. Put constructor arguments after the address and omit them if the constructor had no arguments.

Verify on Filecoin mainnet:

Verify on Calibration testnet:

If Hardhat cannot infer which local contract matches the deployed bytecode, pass the fully qualified contract name:

Sourcify Verification

Sourcify provides decentralized contract verification. Include the Blockscout configuration above and add the following Sourcify configuration:

This configuration enables dual verification on both Sourcify and Blockscout when running the npx hardhat verify task.

If Blockscout verification is also enabled, keep passing constructor arguments when the deployed constructor required them.

For more information, see the Sourcify documentation.

Filfox Verification

Filfox is the native Filecoin explorer with dedicated verification support.

Installation:

Install the @fil-b/filfox-verifier package into your Hardhat project. The FEVM Hardhat Kit already includes this package.

Configuration: Import the plugin in your Hardhat configuration file. This will add the verifyfilfox task into your Hardhat project!

Usage:

The Filfox Hardhat task requires Node.js 20 or later and a compiled Hardhat project. The verifier can discover supported Hardhat deployment artifacts, including hardhat-deploy, Ignition, and standard Hardhat artifacts.

For detailed information, see the @fil-b/filfox-verifier documentation.

Last updated