Verify Contracts with Hardhat
You can deploy smart contracts written in Solidity to a Virtual TestNet using Hardhat. For debugging purposes, it’s recommended to verify smart contracts as you deploy them.
For extensive instructions on how to configure hardhat to perform automatic or explicit code-based verification, explore the following guide:
By default, contracts verified on a TestNet are private. But depending on the visibility setting of the Public Explorer, the code may be visible externally. Before verifying a contract, check if the Public Explorer option is enabled and how you’ve set the verification visibility.
At the moment, the @tenderly/hardhat-tenderly
plugin for Hardhat is compatible with Hardhat up to version 2.22.0
.
npm install hardhat@2.22.0
Create a TestNet
- Create a TestNet by following this guide.
- Fund specific deployer accounts used in Hardhat deploy scripts.
- Copy the Public RPC URL.
Install Tenderly CLI
Install Tenderly CLI and use it to log in:
brew tap tenderly/tenderly
brew install tenderly
tenderly login
Install tenderly-hardhat plugin
npm install --save-dev @tenderly/hardhat-tenderly
Configure hardhat
Necessary configuration is:
- Import the plugin.
- Call
tenderly.setup()
, and activate automatic verifications throughautomaticVerifications
config set totrue
. - Add an entry to
networks
of Hardhat config, name itvirtualMainnet
and paste the RPC URL from Step 1. - Add
tenderly
config and paste yourproject
andusername
.
It’s recommended to name custom networks by prefixing the name with virtual
for easier distinction from actual networks.
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as tenderly from "@tenderly/hardhat-tenderly";
tenderly.setup({ automaticVerifications: true });
const config: HardhatUserConfig = {
solidity: "0.8.19",
networks: {
virtualMainnet: {
url: process.env.TENDERLY_VIRTUAL_MAINNET_RPC!,
},
},
tenderly: {
// https://docs.tenderly.co/account/projects/account-project-slug
project: "YOUR PROJECT",
username: "YOUR USERNAME",
},
};
export default config;
Deploy
With automaticVerifications
set to true
, you can just run a deployment script and your contract will be verified.
npx hardhat run scripts/deploy.ts --network virtualMainnet
Check the dashboard
In the Dashboard, go to Contracts and open Virtual Contracts tab, where you’ll find your contract.