Virtual TestNets are live! ⚡️ Test and stage dapps on real-time production data.
Get started →

All Products

Virtual TestNets
Frameworks
Hardhat

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

  1. Create a TestNet by following this guide.
  2. Fund specific deployer accounts used in Hardhat deploy scripts.
  3. Copy the Public RPC URL.

Install tenderly-hardhat plugin

npm install --save-dev @tenderly/hardhat-tenderly

Configure hardhat

Necessary configuration is:

  1. Import the plugin.
  2. Call tenderly.setup(), and activate automatic verifications through automaticVerifications config set to true.
  3. Add an entry to networks of Hardhat config, name it virtualMainnet and paste the RPC URL from Step 1.
  4. Add tenderly config and paste your project and username.

It’s recommended to name custom networks by prefixing the name with virtual for easier distinction from actual networks.

hardhat.config.ts
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.