How to Deploy with Hardhat and Verify Your Smart Contract with the Blockscout UI

Learn how to verify smart contracts using Hardhat and the Blockscout UI. Ensure transparency, build user trust, and unlock full read-write interaction across EVM chains with Blockscout’s smart contract tools.

smart contract verification, verify smart contract, EVM contract verification, Hardhat deployment, verify contracts Hardhat, Blockscout verification, EVM explorer

Verifying smart contracts is a vital step in ensuring transparency and trust in blockchain applications. Through verification, users can review the source code of deployed contracts, fostering confidence and facilitating deeper interaction with decentralized systems.

Blockscout simplifies this process across various EVM-compatible chains and this is just one of the features that Blockscout offers for comprehensive smart contract coverage, along with advanced capabilities for reading, writing, and interacting with contracts and proxies. In this article, we’ll guide you through verifying your smart contracts directly through the Blockscout UI using Hardhat to deploy the contracts.

smart contract explorer, blockchain transparency, verify Solidity contract, Hardhat contract verify, Blockscout UI

Step 1. Set up Project with Hardhat.

Before proceeding, ensure that you have Node Package Manager (NPM) installed.

1. Initialize a new project using npm.

Enter the root directory of your system and run.

npm init -y

Terminal screenshot showing npm init command creating package.json file for BlockscoutUI React project with basic configuration including name, version, main entry point, and ISC license

2. Install Hardhat

npm install -- save-dev hardhat

Terminal screenshot showing npm install hardhat command completion for BlockscoutUI project with deprecation warnings, package installation summary, funding requests, and security vulnerabilities report

3. Run the setup wizard

npx hardhat

Terminal screenshot showing Hardhat v2.25.0 initialization wizard with ASCII art logo, TypeScript project setup options, gitignore configuration, and npm dependencies installation for BlockscoutUI project

4. Install hardhat toolbox

npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox

Terminal screenshot showing npm install completion for Hardhat toolbox package with deprecation warnings for lodash and glob packages, installation summary of 355 packages, funding requests, and security vulnerabilities report

Go to your hardhat.config.ts file and make sure the toolbox is added;

import "@nomicfoundation/hardhat-toolbox";

Your file should look like this;


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

const config: HardhatUserConfig = {
  solidity: "0.8.28", // or your version
};

export default config;

Step 2. Setup your Config file

Install dotenv to save your private keys and network URL/RPC info in your editor

Go to the Root of your project and Run;

npm install dotenv

Create a .env file and add your Network info;

Unix

touch .env

Windows

type nul > .env

Add Network Info

echo PRIVATE_KEY=your_private_key_here > .env 
echo SEPOLIA_RPC_URL=your_rpc_key_here >> .env
💡
You can use INFURA for your RPC, or another RPC for example https://sepolia.drpc.org.
💡
Be sure your address associated with the private key has some Sepolia ETH to cover the deployment gas. You can get some from a faucet.

Import Hardhat Ignition to deploy the contract.

Install if you don't have already

npm install --save-dev @nomicfoundation/hardhat-ignition

Check that your hardhat.config.ts looks like the the example below, adding import "@nomicfoundation/hardhat-toolbox";

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-ignition";
import * as dotenv from "dotenv";
dotenv.config();

const config: HardhatUserConfig = {
  solidity: "0.8.28",
  networks: {
    sepolia: {
      url: process.env.SEPOLIA_RPC_URL || "",
      accounts: process.env.PRIVATE_KEY ? [`${process.env.PRIVATE_KEY}`] : [],
    },
  },
};

export default config;

Create a Counter contract

Add this file to your contracts folder and save as Counter.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract Counter {
    uint256 public count;

    // Increment the counter by 1
    function increment() public {
        count += 1;
    }

    // Decrement the counter by 1
    function decrement() public {
        require(count > 0, "Count cannot go below zero");
        count -= 1;
    }

    // Get the current count (not needed but added for clarity)
    function getCount() public view returns (uint256) {
        return count;
    }
}

Create a Deployment module

Go to your Ignition/modules folder and create a file CounterModule.ts for your deployment module or replace the existing one.

import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const CounterModule = buildModule("CounterModule", (m) => {
  const counter = m.contract("Counter");

  return { counter };
});

export default CounterModule;

Deploy using Hardhat ignition

Run

npx hardhat ignition deploy ignition/modules/CounterModule.ts --network sepolia

Terminal screenshot showing Hardhat Ignition deployment of CounterModule smart contract to Sepolia testnet with dotenv configuration, deployment confirmation, batch execution, and deployed contract address

Step 3. Verify on Blockscout UI

Paste the deployed contract address on the search bar and click on the details. Next click the Verify and publish button.

💡
It may take a few minutes for your contract to be recognized in the UI as a deployed contract. Check back if you see EOA rather than contract at first.
Blockscout blockchain explorer showing smart contract details page with contract address, verification status, Verify & publish button highlighted, and contract information including Lock contract name, compiler version, and verification timestamp

You will be directed to the verification page; fill in the details of your smart contract.

Blockscout smart contract verification page showing new verification form with contract address, MIT license selection, verification method dropdown highlighting Solidity single file option, compiler settings, and EVM version configuration

Contract License

This is a legal notice declared at the very top of a smart contract file using the SPDX-License-Identifier. It is an optional field.

Verification method

Blockscout provides up to nine methods for verifying your contracts.

verify on Blockscout, public blockchain explorer, contract security, blockchain UX, verify contract tutorial, Hardhat config, contract verification guide, EVM chain support, open source blockchain tools, developer blockchain tools
  • Solidity (Single file) - Can be used for unverified contracts

  • Solidity (Stardard Json Output) - Can be used for partially verified contracts.

  • Solidity (Sourcify) - Used for contracts verified with sourcify

  • Solidity (Multi-part files) - Can be used for unverified contracts

  • Soldidty (Hardhat) - Used for contracts verified with harhat

  • Solidity (Foundry) - Used for contracts deployed with foundry

  • Vyper (contract) - Can be used for unverified vyper contracts

  • Vyper (Multipart files) - Can be used for unverified multiple vyper contracts

  • Vyper (Stardard Json Output) - Can be used for partially verified vyper contracts.

💡
Use the Solidity (Standard JSON Output) file for partially verified contracts. Single/Multi file methods do not work with partial verification.

Selecting a verification method will generate a set of configuration options based on the chosen method. For example, when using Solidity Standard JSON Output, you need to import your JSON file and select your compiler version.

verify Solidity contract, Hardhat contract verify, Blockscout UI, smart contract source code, blockchain trust, smart contract audit, open source contracts, EVM smart contracts, decentralized application contracts, contract ABI, contract bytecode, contract metadata, contract proxy verification, verify proxy contract, Hardhat plugin

Add your extracted JSON

⚠️
If hardhat is used to deploy contracts, the standard json is obtained from artifacts/build-info/{build_hash}.json file

The standard JSON file includes additional information that is not used in the verification process. Extract the information inside the "input": object and save as its own JSON, then drop that saved file into the interface.

To extract, you may want to prettify the JSON to find the input object.
Shift + Alt + F (Windows/Linux)
Shift + Option + F (Mac)
and select prettier json format

Original example JSON:

Extracted example JSON:

You can also use chatgpt or other ai assistance to easily extract this object. Be sure the file starts with { (delete the input: before the object).

{
  "language": "Solidity",
  "sources": {
    "contracts/Counter.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.28;\n\ncontract Counter {\n    uint256 public count;\n\n    // Increment the counter by 1\n    function increment() public {\n        count += 1;\n    }\n\n    // Decrement the counter by 1\n    function decrement() public {\n        require(count > 0, \"Count cannot go below zero\");\n        count -= 1;\n    }\n\n    // Get the current count (not needed but added for clarity)\n    function getCount() public view returns (uint256) {\n        return count;\n    }\n}\n\n"
    }
  },
  "settings": {
    "evmVersion": "paris",
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "abi",
          "evm.bytecode",
          "evm.deployedBytecode",
          "evm.methodIdentifiers",
          "metadata"
        ],
        "": ["ast"]
      }
    }
  }
}

Example of JSON which only contains the information contained in the input object.

Click on the Verify and publish button. The Exact Match verification may take a short while to propagate in the explorer UI.

💡
If the verification process is greyed out or stuck in a loop, refresh the page/contract to check if the verification is successful.
Blockscout verification, EVM explorer, smart contract explorer, blockchain transparency, verify Solidity contract, Hardhat contract verify, Blockscout UI, smart contract source code, blockchain trust, smart contract audit, open source contracts, EVM smart contracts, decentralized application contracts, contract ABI, contract bytecode, contract metadata, contract proxy verification, verify proxy contract, Hardhat plugin, Etherscan alternative, Blockscout explorer, multichain verification, contract interaction tools, read smart contract, write smart contract, smart contract tools, dapp developer tools, Hardhat deploy, verify on Blockscout

Conclusion

Verifying smart contracts through the Blockscout UI is an effective way to enhance transparency, trust, and credibility in your decentralized applications. Making your source code public allows users and developers to inspect, audit, and interact with your contracts more confidently. 

Blockscout’s support for multiple verification methods streamlines the process across various EVM-compatible networks, and its user-friendly interface, combined with advanced tools for interacting with both contracts and proxies, gives developers a significant edge over manual or CLI-based verification methods.