Hardhat

Definition:

Hardhat is an open-source Ethereum development environment built on Node.js that enables Solidity developers to compile, deploy, test, and debug smart contracts using JavaScript or TypeScript scripts — providing Hardhat Network (a built-in local EVM with stack trace support and console.log for Solidity), a flexible plugin ecosystem, and a task-based automation system that made it the dominant smart contract development framework from approximately 2020 to 2022, remaining widely used for production deployments and JavaScript-native teams. Hardhat was built by the Nomic Foundation (formerly Nomiclabs).


Core Components

Hardhat Network:

A built-in local Ethereum node with developer features:

  • EVM with JavaScript VM or optional hardhat-network-helpers for mainnet forking
  • Stack traces — when a Solidity transaction reverts, Hardhat shows which line in Solidity caused the revert (a feature unavailable in Ganache)
  • console.log in Solidity — via import "hardhat/console.sol" enabling console.log(...) calls from Solidity
  • Mining mode: manual (mine only on command), interval, or auto (mine each tx)

Hardhat Tasks:

Hardhat wraps scripts as tasks — reusable, composable automation units:

“`bash

npx hardhat compile

npx hardhat test

npx hardhat run scripts/deploy.js –network mainnet

npx hardhat verify –network mainnet 0xContractAddress constructor_args

“`

TypeScript Support:

Hardhat has first-class TypeScript integration:

  • Auto-generates TypeScript types for contracts (via typechain plugin)
  • All scripts can be fully typed: Contract, Signer, BigNumber types

Testing in Hardhat

Hardhat integrates with Mocha (test framework) and Chai (assertions):

“`typescript

import { expect } from “chai”;

import { ethers } from “hardhat”;

describe(“MyToken”, function () {

it(“Should transfer tokens”, async function () {

const [owner, recipient] = await ethers.getSigners();

const token = await ethers.deployContract(“MyToken”, [1000]);

await token.transfer(recipient.address, 100);

expect(await token.balanceOf(recipient.address)).to.equal(100);

});

});

“`

Mainnet Forking:

“`typescript

// hardhat.config.ts

networks: {

hardhat: {

forking: {

url: “https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY”,

blockNumber: 18000000

}

}

}

“`


Plugin Ecosystem

Hardhat’s plugin system is its greatest strength for complex projects:

Plugin Purpose
@nomicfoundation/hardhat-toolbox Bundle: ethers.js, chai, mocha, typechain, gas reporter
hardhat-deploy Advanced deployment tracking and named accounts
@openzeppelin/hardhat-upgrades Upgrade proxy deployment and validation
hardhat-gas-reporter Gas usage report per test case
@nomiclabs/hardhat-etherscan Automatic Etherscan contract verification
hardhat-foundry Run Foundry tests from inside Hardhat project

Hardhat vs. Foundry in Practice

Many production codebases use both:

  • Foundry for fast unit tests and fuzzing
  • Hardhat for deployment scripts, Etherscan verification, and TypeScript integration

The hardhat-foundry plugin allows sharing contract source and using both test suites in the same project.


hardhat-deploy: Advanced Deployment

The hardhat-deploy plugin (by Wighawag) extends Hardhat with:

  • Named deployments — track deployed contract addresses across networks
  • Deployment fixtures — reset to a specific deployment state in tests
  • Upgrade support — proxy pattern deployment management
  • Multi-network deployment tracking — record deployment metadata in JSON files

This is the standard approach for complex projects deploying across mainnet, testnets, and L2s simultaneously.


Nomic Foundation

Hardhat is maintained by the Nomic Foundation, a nonprofit focused on Ethereum developer tooling. The Foundation receives grants from the Ethereum Foundation and protocol DAOs to continue Hardhat development.


Related Terms


Sources

Last updated: 2026-04