Hemi
DiscordGithub
  • 🏠Main
    • Welcome to the Hemi Docs
    • Getting Started
      • Developer Quickstart
      • Enthusiast Quickstart
      • Miner Quickstart
    • Network Details
  • ⛰️Foundational Topics
    • The Architecture
      • Consensus and Security Protocols
      • Ethereum Rollups
        • Pros & Cons
        • Decentralized Rollups
      • Sequencer Consensus
        • Proof-of-Stake (PoS)
        • PoS-Only Pitfalls
        • PoS Solutions
      • Proof-of-Proof (PoP)
        • Proof-of-Proof Consensus & Bitcoin Finality
        • Proof-of-Proof vs. Merged Mining
        • Running a PoP Mining
      • Tunnels
        • Ethereum Tunnel
        • Bitcoin Tunnel
      • Ethereum Virtual Machine (EVM)
      • Blocks
      • Transactions
      • Gas
    • Nodes & Clients
      • Node Guides
    • Wallet Support
  • 📖How-To Tutorials
    • Using Hemi
      • Wallet Setup
        • EVM Wallet Setup
        • BTC Wallet Setup
          • Switch Bitcoin Networks
      • Tunnel from Ethereum
        • Tunnel ERC20s via Native Tunnel
        • Tunnel ERC20s via 3rd Party
          • Tunnel via Stargate
      • Tunnel from Bitcoin
        • Tunnel BTC via Native Tunnel
        • Tunnel BTC via 3rd Party
      • Stake
      • Developer Tooling
        • Set Up a Safe Wallet
        • Create a Capsule
      • PoP Mining
        • CLI PoP Miner
          • (Testnet) Add tHEMI to MetaMask
          • (Mainnet) Add PoPPoints to Metamask
        • Web PoP Miner (deprecated)
    • Developing on Hemi
      • General
        • HelloWorld.sol
        • Deploy an ERC-20 Token
      • hVM & hBK
        • Using the hBK Demo App
        • Get Bitcoin Balance with Remix
  • ⚙️Building Bitcoin Apps
    • Introduction
    • Hemi Virtual Machine (hVM)
      • Motivation
      • Feature Summary
      • Deploy on hVM
    • Hemi Bitcoin Kit (hBK)
      • Overview
      • hBK Smart Contract
  • ⚙️Tooling
    • viem
    • Contract Addresses
    • Contract Verification
    • Data Indexing
    • Oracles
  • 📝Incentives
    • Points
    • Grants
    • Retroactive Funding
    • One-Off Spends
  • ⚡Additional Resources
    • Partners
    • FAQ
    • Official Links
    • Brand Kit
  • 📨Send Feedback
    • Bug Report
    • Contact Us
Powered by GitBook
On this page
  • 🏁 Prerequisites
  • 🖥️ Blockscout UI Verification
  • 🚧 Hardhat Verification

Was this helpful?

Edit on GitHub
Export as PDF
  1. Tooling

Contract Verification

📜 TL;DR:

This guide explains how to verify smart contracts deployed on the Hemi blockchain using two methods:

  1. Manual UI-based verification via Blockscout.

  2. API-based verification using Hardhat.


🏁 Prerequisites

  • Hemi RPC URL and deployed contract address.

  • Contract source code available (flattened only if verifying manually via the Hemi Blockscout UI).


🖥️ Blockscout UI Verification

Manual verification is performed directly through the Blockscout UI. This method requires flattening the contract source code and uploading it manually.

1. Flatten the contract

Flattening a contract is necessary when verifying through the UI.

For Hardhat:

npx hardhat flatten contracts/MyContract.sol > MyContractFlattened.sol

For Foundry:

forge flatten src/MyContract.sol > MyContractFlattened.sol

2. Access Hemi Blockscout


3. Input contract information

  • Smart contract / Address: Paste the address that your smart contract was deployed to.

  • Contract license: Select 'No License' unless otherwise specified.

  • Verification method: Choose Solidity (Flattened source code).

  • Is Yul contract: Leave unchecked unless your contract is written in Yul.

  • Include nightly builds: Select only if required.

  • Compiler: Choose the exact version specified in pragma solidity X.X.X in your code.

  • EVM Version: Set to default unless you used a specific EVM version.

  • Optimization enabled: Deselect optimization.

Copy and paste the entire flattened contract code into the Contract code field and click 'Verify & publish'.


4. Submit for verification 🎉

Once all required details are entered, submit the form. BlockScout will compare the uploaded source code with the deployed bytecode. If they match, your contract will be verified.

To confirm verification, search for your contract address on BlockScout. A green check mark next to your contract indicates successful verification.


🚧 Hardhat Verification

1. Install dependencies

If you haven't already installed Hardhat and the verification plugin (adapted for Blockscout), run the following:

npm install --save-dev hardhat @nomiclabs/hardhat-etherscan @nomicfoundation/hardhat-verify

2. Configure Hardhat for Hemi

In your `hardhat.config.js`, set up the Hemi network and include Blockscout API information for contract verification:

require('dotenv').config()
require("@nomiclabs/hardhat-ethers");
require("@nomicfoundation/hardhat-verify");

module.exports = {
  solidity: "0.8.20",
  networks: {
    hemi: {
      url: "https://rpc.hemi.network/rpc",
      chainId: 43111,
      accounts: [`0x${process.env.PRIVATE_KEY}`],
    },
  },
  etherscan: {
    apiKey: {
      // Is not required by blockscout. Can be any non-empty string
      'hemi-mainnet': "abc"
    },
    customChains: [
      {
        network: "hemi-mainnet",
        chainId: 43111,
        urls: {
          apiURL: "https://explorer.hemi.xyz/api",
          browserURL: "https://explorer.hemi.xyz",
        }
      }
    ]
  },
  sourcify: {
    enabled: false
  }
};

3. Verify the contract

Once deployed, you can verify the contract using Hardhat’s `verify` command. Make sure to include any constructor arguments if necessary:

npx hardhat verify --network hemi <DEPLOYED_CONTRACT_ADDRESS> "Constructor Argument 1" "Constructor Argument 2"

4. Verification successful! 🎉

hardhat-verify found one or more errors during the verification process:

Etherscan:
The block explorer's API responded that the contract contracts/MyToken.sol:MyToken at <CONTRACT ADDRESS> is already verified.
This can happen if you used the '--force' flag. However, re-verification of contracts might not be supported
by the explorer (e.g., Etherscan), or the contract may have already been verified with a full match.
PreviousContract AddressesNextData Indexing

Last updated 5 months ago

Was this helpful?

Go to Hemi Blockscout Explorer and navigate to the page.

If you encounter the following error, visit the and search your contract address to confirm verification:

⚙️
Verify & Publish Contract
Hemi Block Explorer