All Products

DevNets
Contract Verification on DevNets

Contract Verification on DevNets

Contract verification is the process of ensuring that the deployed smart contract bytecode matches its source code and has been compiled correctly.

Tenderly uses the contract source code to enhance the execution data, enabling the full potential of our Debugger and other powerful tools. We recommend that you verify your smart contracts to take full advantage of Tenderly’s features.

This quick guide explains how to verify smart contracts on DevNets from the Tenderly Dashboard and via the Tenderly HardHat plugin.

Requirements

To verify a smart contract on DevNets, you need to provide the following:

  • Smart contract source code
  • Exact compiler settings you used to compile the deployed version

How to verify contracts via Tenderly Dashboard

Follow the steps outlined below to verify smart contracts from the Tenderly Dashboard.

Uploading the smart contract source code

There are several ways to upload the smart contract source code via Tenderly Dashboard:

  • Upload a JSON file containing metadata generated by the compiler
  • Paste the source code into the Dashboard
  • Upload the source file from your machine
  • Upload the entire directory with all your smart contracts (easier for contracts with imports from other files)

Verifying a smart contract

With the contract added to your Tenderly project, verify it via the Dashboard by following these steps:

  1. Navigate to the Contracts tab in the lefthand menu.
  2. Click on Verify Contract.
  3. Find the contract address of a contract that’s not verified and paste it into the input field provided in the modal.
  4. Choose between JSON Upload and Contract File Upload to verify the contract.
    • Pick JSON Upload to enter the JSON metadata generated by the Solidity compiler.
    • Select Contract File upload to paste the contract source code directly, upload a single source file, or upload the source directory when importing an entire project, like a Hardhat project.
  5. Contract verification is set to Private by default because that contract is only available inside a single DevNet run.
  6. If the file contains several contracts, pick the one you want to verify (the deployed one to the address shown in Step 2) and repeat the process for others if needed.

If any contract files are missing, a notification will prompt you to add them to complete the verification process.

  1. Fill in the compiler parameters, including the compiler version, optimization used (true/false), optimization count, EVM version (latest set by default), and library (one or more library name-address pairs, if required).

Be sure to enter the precise compiler settings. Any mismatch will result in failure to validate.

  1. Click the Finish button to complete the verification.

How to verify contracts via the Tenderly HardHat plugin

Follow the steps below to verify a smart contract on DevNets using the Tenderly HardHat plugin. You’ll learn how to verify contracts via code that can be checked into source control.

Setting up the environment

To use a specific Tenderly contract verification method, you need a Hardhat project and a Tenderly API key.

  1. Start with a Hardhat project and follow the guides.
  2. Authenticate with Tenderly using tenderly login or by generating an API key in the Dashboard and placing it in ~/.tenderly/config.yaml under access_key.

Installing the Tenderly Hardhat plugin

  1. Install the Tenderly plugin for Hardhat:

    npm install --save-dev @tenderly/hardhat-tenderly
    
  2. Add the following to .gitignore to exclude the deployments directory from version control:

    # hardhat-tenderly plugin
    deployments
    
  3. In hardhat.config.js, import the Tenderly Hardhat library and initialize the plugin by calling setup().

example.ts
import * as tdly from '@tenderly/hardhat-tenderly';
tdly.setup();

If you prefer manual verification, disable automatic verification with the automaticVerifications: false argument:

example.ts
tdly.setup({ automaticVerifications: false });
  1. Extend the hardhat config with Tenderly configuration object:
example.ts
const config: HardhatUserConfig = {
  solidity: {...},
  networks: {...},
  tenderly: {
    project: 'my-project-slug',
    username: 'my-username'
  }

Replace the my-project-slug and my-username with appropriate values you can find in the dashboard.

Verifying a smart contract

Automatic verification: By default, the plugin automatically verifies contracts after deployment. It’s necessary to await for the contract to be deployed for the plugin to verify the contract:

example.ts
const Ctrct = await ethers.getContractFactory('Ctrct');
const ctrct = await Ctrct.deploy();
 
await ctrct.deployed(); // hardhat-tenderly plugin verifies the contract automatically

Simple manual verification: To call the verification explicitly, use tenderly.verify(). You need to pass a minimal configuration object that includes the contract name and address. Learn how to manually verify your contracts.