Skip to main content

Verify a smart contract on Monad Explorer using Hardhat

Once your contract is deployed to a live network, the next step is to verify its source code on the block explorer.

Verifying a contract means uploading its source code, along with the settings used to compile the code, to a repository (typically maintained by a block explorer). This allows anyone to compile it and compare the generated bytecode with what is deployed on chain. Doing this is extremely important in an open platform like Monad.

note

Currently, the block explorer is not public; this page will be updated as soon as it is.

We appreciate your patience.

In this guide we'll explain how to do this in the Monad explorer.

1. Setting up configuration variables

A Hardhat project can use configuration variables for user-specific values or for data that shouldn't be included in the code repository.

To set a configuration variable you can use the following command:

npx hardhat vars set <variable_name>

For example, to set the MONAD_RPC_URL variable, you would enter the following command:

npx hardhat vars set MONAD_EXPLORER_URL
note

Make sure you don't include the /api part when setting MONAD_EXPLORER_URL configuration variable.

Then enter the desired value for this variable at the prompt:

Enter value: ********************************

Similarly you can set up the MONAD_CHAIN_ID variable.

warning

Configuration variables are stored in plain text on your disk. Avoid using this feature for data you wouldn’t normally save in an unencrypted file. Run npx hardhat vars path to find the storage's file location.

2. Update your hardhat.config.ts file to include the monadDevnet configuration

import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";
import { vars } from "hardhat/config";

const config: HardhatUserConfig = {
solidity: "0.8.27",
...
etherscan: {
apiKey: `DUMMY_VALUE_FOR_BLOCKSCOUT`,
customChains: [
{
network: "monadDevnet",
chainId: Number(vars.get("MONAD_CHAIN_ID")),
urls: {
browserURL: vars.get("MONAD_EXPLORER_URL"),
apiURL: `${vars.get("MONAD_EXPLORER_URL")}/api`,
},
},
...
],
},
};

export default config;

Note: currently the Monad explorer is Blockscout-based and does not require an API key. We use a dummy placeholder value DUMMY_VALUE_FOR_BLOCKSCOUT to avoid errors.

3. Verify the smart contract

Use the following command to verify the smart contract:

npx hardhat verify <contract_address> --network monadDevnet

On successful verification of smart contract, the output should be similar to the following:

note

Currently, the block explorer is not public; this page will be updated as soon as it is.

We appreciate your patience.

Successfully submitted source code for contract
contracts/GMonad.sol:GMonad at <contract_address>
for verification on the block explorer. Waiting for verification result...

Successfully verified contract GMonad on the block explorer.
<block_explorer_url>/address/0x690BE9B15b84c6487965d1cbf3372A9FB07A6eE1#code

Using the link in the output above, you can view the verified smart contract on the explorer.