Using Hardhat Plugins for Etherscan and Tenderly

Introduction

In the rapidly evolving world of Ethereum development, Hardhat stands out as a flexible and powerful framework. To streamline your workflow, two essential plugins are the
Etherscan plugin
and the
Tenderly plugin.
This article dives deep into installation, configuration, and best practices for verifying on Etherscan and leveraging Tenderly’s simulation platform.

What Are Hardhat Plugins

Hardhat plugins extend the core framework with specialized tasks, commands, and utilities. They allow you to integrate third-party services, automate repetitive actions, and customize your build and deployment process.

  • Etherscan plugin: Automates contract verification on Etherscan.
  • Tenderly plugin: Enables forking, simulation, and advanced debugging via Tenderly’s platform.

Installation

Begin with a Hardhat project. If you don’t have one:

  1. Initialize: npm init -y
  2. Install Hardhat: npm install --save-dev hardhat
  3. Create config: npx hardhat and select “Create a basic sample project.”

Then install the plugins:

  • npm install --save-dev @nomiclabs/hardhat-etherscan
  • npm install --save-dev @tenderly/hardhat-tenderly

Configuration

In your hardhat.config.js, require both plugins and set API keys:

require(@nomiclabs/hardhat-etherscan)
require(@tenderly/hardhat-tenderly)

module.exports = {
  solidity: 0.8.17,
  networks: {
    mainnet: {
      url: process.env.INFURA_URL,
      accounts: [process.env.PRIVATE_KEY]
    },
    ropsten: {
      url: process.env.ALCHEMY_URL,
      accounts: [process.env.PRIVATE_KEY]
    }
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY
  },
  tenderly: {
    project: process.env.TENDERLY_PROJECT,
    username: process.env.TENDERLY_USERNAME,
    privateVerification: true
  }
}

Note: Store keys in a .env file and load via dotenv to avoid committing secrets.

Plugin Options at a Glance

Plugin Option Description
etherscan apiKey Your Etherscan API key for contract verification.
tenderly project, username Credentials to connect to your Tenderly workspace.
tenderly privateVerification Enables private contract source publication.

Verifying Contracts on Etherscan

Once deployed, verification is as simple as:

npx hardhat verify –network ropsten ltDEPLOYED_CONTRACT_ADDRESSgt ltCONSTRUCTOR_ARG1gt ltCONSTRUCTOR_ARG2gt
  • The plugin fetches your compiled ABI and metadata.
  • It sends a verification request to Etherscan’s API.
  • Results will appear in your Hardhat console with a link to the verified source.

Tip: If your contract uses libraries, pass --libraries flags or configure them in your Hardhat config.

Leveraging Tenderly for Simulation Debugging

Tenderly offers advanced on-chain simulation, transaction insights, and forked network testing. With the Hardhat plugin you can:

  • Create a forked network: Simulate state at any block.
  • Run local traces: Inspect stack, storage changes, and gas usage.
  • Automate alerts: Integrate with CI to detect anomalies.

Example: Fork and Simulate

npx hardhat tenderly:fork --network mainnet --blockNumber 16234567

This command will spin up a local Hardhat network that mirrors mainnet at the specified block. You can then send transactions or run tests against this snapshot.

Transaction Simulation

  1. Deploy to a fork: npx hardhat run scripts/deploy.js --network tenderly
  2. Simulate a function call: npx hardhat tenderly:simulate --to ltCONTRACT_ADDRESSgt --data ltINPUT_DATAgt
  3. View detailed trace gas report in your Tenderly dashboard (tenderly.co).

Automating Verification in CI/CD

Integrating these plugins into CI/CD pipelines ensures that each deployment is verified and simulated automatically.

  • Set environment variables in your CI (GitHub Actions, GitLab CI, etc.).
  • Create a script in package.json:
    verify-and-simulate: npx hardhat verify --network NETWORK ADDRESS  npx hardhat tenderly:simulate --to ADDRESS

  • Invoke it after each deployment step.

Best Practices Tips

  • Modular Config: Keep network and plugin settings in separate files, then import into hardhat.config.js.
  • Version Matching: Ensure your compiler version matches the one on Etherscan/Tenderly to avoid mismatches.
  • Library Handling: Always specify library addresses if using link. Use hardhat-etherscan’s libraries option.
  • Private Verification: Use Tenderly’s private verification for proprietary contracts.
  • Monitor Usage: Track API usage to avoid rate limits on Etherscan and Tenderly.

Conclusion

By integrating the Etherscan and Tenderly plugins into your Hardhat workflow, you elevate your development process with automated verification, robust simulation, and deep transaction insights. This leads to more secure, transparent, and reliable smart contracts. Whether you’re a bootstrapping startup or an enterprise team, these tools help maintain quality and trust in your decentralized applications.

Explore further:
Hardhat Docs
Etherscan API
Tenderly Platform


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *