Using Hardhat
How to verify smart contract on Mode using hardhat
Introduction
Verifying a smart contract on the blockchain is an essential step to ensure its transparency, security, and ease of interaction for users and other developers. Hardhat has emerged as a powerful tool for compiling, testing, deploying, and verifying smart contracts.
This tutorial will guide you through the process of verifying your smart contract on Mode network using Hardhat.
Prerequisites
Before diving into the verification process, ensure you have the following ready:
Hardhat Installed: A foundational requirement, as Hardhat will be used for compiling, deploying, and verifying your smart contract.
Node.js and NPM: Hardhat runs on Node.js, and you'll use NPM (Node Package Manager) to install the Hardhat verification package.
Ethereum Wallet: A wallet like MetaMask, connected to the Mode network, is essential for deploying and managing your contracts.
Your Smart Contract Deployed: A smart contract already deployed on the Mode network. This guide assumes you've completed the deployment process but if you haven' t please check Deploying a Smart Contract
Step 1: Installing Hardhat Verify Package
The first step is to integrate verification capabilities into your Hardhat environment. This is achieved by installing the @nomicfoundation/hardhat-verify plugin. Run the following command in your project's root directory:
Step 2: Configuring Hardhat
With the verification plugin installed, you need to import it and enable Sourcify integration in your hardhat.config.ts
. This configuration aids in the verification process by ensuring your source code is published and verified through Sourcify.
Add the following lines to your hardhat.config.ts:
You hardhat.config file should look something like this:
Step 3: Verifying Your Contract
With your project configured for verification, you're ready to verify your smart contract on the Mode network. Replace <contract-address> with the actual address of your deployed contract. The command below initiates the verification process:
For Testnet Verification
If your contract is on the Mode testnet, use the following command, replacing CONTRACT_ADDRESS
with your contract's actual address:
For Mainnet Verification
For contracts deployed on the Mode mainnet, the command adjusts slightly to point to the mainnet explorer:
NB: Ensure the network name in your command aligns with your hardhat.config.ts
setup.
This command communicates with the Mode network (as defined in your Hardhat configuration) and submits your contract's source code and metadata for verification. Upon successful verification, your contract's source code will be publicly visible on the blockchain, associated with its on-chain address. You should get a similar response to the one below:
Conclusion
Verifying your smart contract on Mode using Hardhat not only enhances the transparency and credibility of your project but also significantly improves the end-user experience by facilitating easier interactions and verifications. Following the steps outlined in this guide, developers can ensure their contracts are verified and open for scrutiny, fostering a more secure and trustworthy ecosystem.
Further Resources
Mode Network Explorer (For checking contract verification status)
Last updated