Verifying Smart Contracts
In this article, you’ll learn how to verify smart contracts in Etherscan with hardhat and the hardhat deploy plugin.Objectives
By the end of this lesson, you should be able to:- Verify a deployed smart contract on Etherscan
- Connect a wallet to a contract in Etherscan
- Use etherscan to interact with your own deployed contract
Overview
Verifying smart contracts plays an important role in providing security and certainty to the users of your decentralized applications. By offering full visibility of the source code of your smart contract, you provide confidence and transparency of the intention of the code that is being executed. The way smart contracts are verified is by simply uploading the source code and contract address to services such as Etherscan. Once the contract is verified, the Etherscan explorer shows a status like the following image:
- Getting an Etherscan key
- Configuring Hardhat
- Verifying
Getting an Etherscan key
In order to obtain an Etherscan API key, visit Etherscan and create an account. Then, go to https://etherscan.io/myapikey and create an API key by clicking the Add button:
Configuring Hardhat
You can configure the Etherscan API Key for each different network. For example, include the following to thehardhat.config.ts
file for Base Sepolia:
.env
file the following:
Verifying
You verify in base, and to do so, simply run the following command: