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

Verify a contract with Hardhat

Who this is for: developers who've deployed a contract with Hardhat and want its source code visible and callable on the explorer.

Prerequisites: a contract already deployed. See Deploy a contract with Hardhat.

Time: a couple of minutes.

1

1. Confirm the verify plugin is installed

@nomicfoundation/hardhat-toolbox (which bundles hardhat-verify); if you scaffolded via Quickstart, it already is.

2

2. Add the verifier config to hardhat.config.js

hardhat.config.js
module.exports = {
  // ...existing config
  etherscan: {
    apiKey: {
      lumiaBeam: process.env.LUMIA_EXPLORER_API_KEY, // {{TODO: confirm whether an API key is required at all}}
    },
    customChains: [
      {
        network: "lumiaBeam",
        chainId: 2030232745,
        urls: {
          apiURL: "{{TODO: confirm: explorer API URL for Beam}}",
          browserURL: "{{TODO: see /reference/explorers for the browser URL}}",
        },
      },
    ],
  },
};
3

3. Run verification against your deployed address

npx hardhat verify --network lumiaBeam <DEPLOYED_CONTRACT_ADDRESS> <constructor arg 1> <constructor arg 2>

List constructor arguments in the same order your contract's constructor takes them; omit this if your contract has none.

Verify it worked

Open the contract's address on the Beam explorer (see Block explorers). The Contract tab shows your source code and a Read/Write Contract panel once verification succeeds.

Troubleshooting

hardhat verify fails with an API/network error

The explorer API URL or key requirement isn't confirmed yet for Lumia. See the TODO above. Check whether Lumia's explorer (Blockscout-based, per /reference/explorers) needs a key at all before assuming your key is wrong.

"Already verified" but the explorer shows no source

This usually means a prior partial verification attempt; try again with the exact same compiler version and settings used to deploy.

Constructor argument mismatch error

The arguments passed to hardhat verify must exactly match, in order and type, what was passed to deploy().

Was this helpful?