@teller-protocol/hardhat-tenderly v1.6.3
hardhat-tenderly
Hardhat plugin for integration with Tenderly.
This repo represents the hardhat-tenderly plugin. With its functionalities, you can verify contracts on the Tenderly platform. Verification represents an entry point into Tenderly's functionalities. With verified contracts, you can use various features like debugger or simulations and forks. This repo will make it possible to verify your contracts with ease, so you can focus on building your dapp.
You can read about hardhat-tenderly's verification features in detail here.
Here's a brief description. There are three modes you can configure to verify your contracts and these are called Verification Modes:
- Private verification mode - Only you or people who share the project with you may see the source code of the contract and interact with it.
- Public verification mode - Anyone can see the source code of the contract and interact with it.
- Fork verification mode - Verify deployed contract on a tenderly fork.
Also, there are three ways of how you can actually do the verification based on the mode you configured in verification modes. These ways are called Verification Approaches:
- Automatic verification approach - The plugin will automatically verify your contracts after each deployment.
- Manual verification approach - You will have to manually verify the contracts via plugin method calls.
- Task verification approach - Verify your contracts via
tenderly:verifyhardhat task.
Installation
npm install --save-dev @tenderly/hardhat-tenderlyAnd add the following statement to your hardhat.config.js or hardhat.config.ts:
const tdly = require("@tenderly/hardhat-tenderly");
tdly.setup();Or, if you are using typescript:
import * as tdly from "@tenderly/hardhat-tenderly";
tdly.setup();Installing tenderly cli
In order to use all the plugin's functionalities, it will be necessary to have a tenderly config file.
This file will be automatically created after you install tenderly cli and log in with tenderly login.
To install tenderly cli, follow the installation steps at tenderly-cli. After that, run:
tenderly login --authentication-method access-key --access-key {your_access_key} --forceAccess key can be found under Settings->Authorization->Generate new access key in your Tenderly dashboard.
Verification Modes
This section explains three modes you can configure to verify your contracts.
First, you need to add the tenderly field inside the HardhatConfig structure in hardhat.config.ts:
module.exports = {
solidity: {
...
},
networks: {
...
},
tenderly: {
username: "tenderly", // tenderly username (or organization name)
project: "project", // project name
privateVerification: false // if true, contracts will be verified privately, if false, contracts will be verified publicly
}
}Warning : Username can be your own and the username of the organization. Which one, it depends on who is the owner of the project you are trying to verify your contracts on. If the project belongs to the organization you are part of, It should be filled with organization username, otherwise your own username. The quickest and most secure way to make sure to which party the project belongs to is to look at the url of the particular project. You will see something like: https://dashboard.tenderly.co/Tenderly/project/contracts. You can take the username and project from there. In this case the username is Tenderly and the project is project.
Private verification mode
In order to configure private verification mode, set privateVerification to true inside the tenderly field inside hardhat.config.ts.
Also, the --network flag must NOT be set to tenderly when running npx hardhat run command, or fork verification mode will be configured.
Public verification mode
In order to configure public verification mode, set privateVerification to false inside the tenderly field inside hardhat.config.ts.
Also, the --network flag must NOT be set to tenderly when running npx hardhat run command, or fork verification mode will be configured.
Fork verification mode
In order to configure fork verification mode, set privateVerification to false inside the tenderly field inside hardhat.config.ts.
To configure the fork you want to verify the contracts on, set the tenderly network inside HardhatConfig structure in hardhat.config.ts:
module.exports = {
solidity: {
...
},
networks: {
... // other networks
sepolia: {
url: "https://sepolia.gateway.tenderly.co/...",
accounts: ["0x..."],
},
...,
// -------- CONFIGURE FORK HERE -----------
tenderly: {
url: "https://rpc.tenderly.co/fork/...",
accounts: ["0x..."]
}
// ----------------------------------------
},
tenderly: { // as before
username: "tenderly",
project: "project",
privateVerification: false
}
}Parameters:
urlis the fork rpc url that you can find on the dashboard in the info tab of the particular fork you want to verify your contracts on.accountsfield should be your private key or mnemonic as with every other network.- Also, the
--networkflag MUST be set totenderlywhen runningnpx hardhat runcommand in order to configure fork verification mode.
Verification Approaches
This section explains the steps you take to actually verify your contracts. You can verify your contracts Automatically, Manually or via Task.
For every of these three approaches, you can configure the mode of verification. Either Private, Public or Fork verification mode. See how to configure these modes in Verification Modes section above.
Automatic verification approach (Recommended)
This approach will automatically verify the contract after deployment. Precisely, when you call the deployed() function as in:
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();The plugin will wait for the contract to be deployed and verify it afterwards.
If you wish to turn off automatic verification, you can do it in hardhat.config.ts:
import * as tdly from "@tenderly/hardhat-tenderly";
tdly.setup({
automaticVerifications: false,
});Manual verification approach
This plugin extends the HardhatRuntimeEnvironment by adding a tenderly field whose type is Tenderly.
With this approach, you can use tenderly.verify to trigger manual contract verification.
The same method is called when verifying contracts automatically.
This is an example on how you can call it from your deploy script:
import { ethers, tenderly } from "hardhat";
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
await tenderly.verify({
name: "Greeter",
address: greeter.address,
libraries: {
LibraryName1: "0x...",
LibraryName2: "0x..."
}
});verify accepts contracts as variadic arguments, so you can verify multiple contracts at once:
const contracts = [
{
name: "Greeter",
address: "0x...",
libraries: { ... }
},
{
name: "Greeter2",
address: "0x...",
libraries: { ... }
},
];Task verification approach
This plugin implements the concept of hardhat task to verify your contracts.
The task, tenderly:verify, is invoked as:
npx hardhat tenderly:verify Greeter=0x... --network {network_name}For more information on how to use tenderly:verify task, run npx hardhat help tenderly:verify command.
More verification approaches
You can also verify your contracts via exposed API calls. Although this is not recommended, you can fill the request and call some of the following methods:
verifyMultiCompilerAPI(request: TenderlyVerifyContractsRequest)verifyForkMultiCompilerAPI(request: TenderlyVerifyContractsRequest)
For more information on how to use these methods, you can check out their javadocs.
Troubleshooting
If you are having trouble with the plugin and want to contact support, you can run the deploy script with the following --verbose flag as so:
npx hardhat run scripts/{your_deploy_script_here.js} --network {network_name} --verbose > tenderly.log 2>&1or you can run the task with the same --verbose flag:
npx hardhat tenderly:verify Greeter=0x... --network {network_name} --verbose > tenderly.log 2>&1This will create a tenderly.log file that you can send to our customer support engineers for investigation.