Automatic Contract Verification

The Tenderly Hardhat plugin verifies contracts publicly by default, unless you configure it to use the private mode.

Automatic contract verification is a part of Tenderly’s Hardhat plugin. This method of verification happens seamlessly when you’re deploying a contract using Ethers.js. The only additional step is to enable the automatic verification in Tenderly in your hardhat.config.ts file.

example.tsx
// File: hardhat.config.ts
import * as tdly from '@tenderly/hardhat-tenderly';
tdly.setup({ automaticVerifications: true });
// automaticVerifications defaults to `true`, same as:
// tdly.setup();

The code example below deploys the Greeter contract and verifies it in Tenderly. The only step is to wait for the confirmation of contract's deployment by calling await greeter.waitForDeployment() , so the plugin gets a chance to verify the contract after it's confirmed.

example.tsx
// File: scripts/greeter/automatic.ts
import { ethers } from 'hardhat';
 
async function main() {
  let greeter = await ethers.deployContract('Greeter', ['Hello, Hardhat!']);
 
  greeter = await greeter.waitForDeployment();
 
  console.log('{Greeter} deployed to', await greeter.getAddress());
}
 
main().catch(error => {
  console.error(error);
  process.exitCode = 1;
});

Next, execute the Hardhat run command:

example
npx hardhat run scripts/greeter/automatic.ts --network ropsten

After executing the command, you’ll receive the following output:

Output of npx hardhat run scripts/greeter/automatic.ts --network ropsten

To check whether the operation execution was successful, you should access your Tenderly Dashboard by clicking the link printed in the console output.

In the Tenderly Dashboard, you should see something similar to the following.

Verified contract in Tenderly Dashboard

When you click Add to Project, you’ll have an overview of the Greeter.sol with its source code. Next to it, you can see console.sol - a Solidity Library by Hardhat that was included automatically.

Source code of the verified Contract added to a project

How automatic contract verification works

When you call Ethers’ await greeter.waitForDeployment(), the plugin will automatically detect the contract and its address, upload the source code, and let Tenderly verify against the contract deployed on the selected network.

It will automatically detect all the libraries and contracts imported by the one you've just deployed, and include that information for verification.

Essentially, automatic verification is a no-code solution. This isn't the case with other verification methods.

When is automatic verification applicable?

Automatic verification works only when deploying new contracts. If you’re working with a previously deployed Smart Contract, or you require a greater level of configuration control and flexibility, so you should explore manual contract verification methods.