Skip to main content

Verify a smart contract on Monad 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.

In this guide we'll explain how to do this using Hardhat.

1. Update your hardhat.config.ts file

import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";
const config: HardhatUserConfig = {
solidity: {
version: "0.8.28",
settings: {
metadata: {
bytecodeHash: "none", // disable ipfs
useLiteralContent: true, // use source code
},
},
},
networks: {
monadTestnet: {
url: "https://testnet-rpc.monad.xyz",
chainId: 10143,
},
},
sourcify: {
enabled: true,
apiUrl: "https://sourcify-api-monad.blockvision.org",
browserUrl: "https://testnet.monadexplorer.com",
},
// To avoid errors from Etherscan
etherscan: {
enabled: false,
},
};
export default config;

2. Verify the smart contract

npx hardhat verify <contract_address> --network monadTestnet

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

Successfully verified contract Lock on Sourcify.
https://testnet.monadexplorer.com/contracts/full_match/10143/<contract_address>/