Configs2026年5月14日·1 分钟阅读

Hardhat — Ethereum Development Environment for Professionals

Hardhat is a development environment for compiling, deploying, testing, and debugging Ethereum smart contracts. It features a built-in local network (Hardhat Network) with advanced debugging capabilities like Solidity stack traces, console.log, and mainnet forking. Hardhat uses a JavaScript/TypeScript task and plugin system for extensibility.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Stage only · 29/100Stage only
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Stage only
信任
信任等级:Established
入口
Hardhat
通用 CLI 安装命令
npx tokrepo install 59935d2e-4f90-11f1-9bc6-00163e2b0d79

Introduction

Hardhat is a JavaScript and TypeScript development environment for Ethereum smart contracts maintained by Nomic Foundation. It provides a flexible task runner, a built-in local blockchain with advanced debugging, and a rich plugin ecosystem. Hardhat is one of the most popular choices for professional Solidity development teams.

What Hardhat Does

  • Compiles Solidity contracts with configurable compiler versions and optimization settings
  • Runs JavaScript or TypeScript tests using Mocha and Chai with built-in assertions
  • Provides Hardhat Network, a local Ethereum node with Solidity stack traces and console.log
  • Supports mainnet forking to simulate transactions against live chain state
  • Deploys contracts via scripts with built-in provider and signer management

Architecture Overview

Hardhat is built as a task runner where each command (compile, test, deploy) is a task that can be overridden or extended via plugins. The Hardhat Runtime Environment (HRE) is injected into scripts and tests, providing access to ethers.js, network configuration, and artifacts. Hardhat Network is an in-process EVM powered by EDR (Ethereum Development Runtime) written in Rust for improved performance. Plugins hook into compilation, testing, and deployment phases.

Self-Hosting & Configuration

  • Initialize with npx hardhat init and select a project template (JavaScript, TypeScript, or empty)
  • Configure networks, compiler, and paths in hardhat.config.ts
  • Install plugins like @nomicfoundation/hardhat-toolbox for a batteries-included setup
  • Set INFURA_API_KEY or ALCHEMY_API_KEY in .env for testnet and mainnet deployment
  • Use hardhat-deploy plugin for reproducible, deterministic deployments

Key Features

  • Solidity stack traces pinpoint the exact line where a transaction reverts
  • console.log in Solidity contracts outputs to the terminal during tests
  • Mainnet forking lets you test against real contract state at any block number
  • TypeScript-first with full type generation from contract ABIs via TypeChain
  • Plugin ecosystem includes verification (Etherscan), gas reporting, and coverage

Comparison with Similar Tools

  • Foundry — Rust-based with Solidity-native tests and faster execution; Hardhat offers a richer JS plugin ecosystem
  • Truffle — Earlier JavaScript framework now largely superseded; Hardhat has better debugging and TypeScript support
  • Brownie — Python-based framework; Hardhat is the standard for JavaScript/TypeScript teams
  • Remix — Browser-based IDE for quick prototyping; Hardhat is designed for full project lifecycles

FAQ

Q: Can I use Hardhat with TypeScript? A: Yes. Hardhat has first-class TypeScript support. Running npx hardhat init offers a TypeScript project template.

Q: How does mainnet forking work? A: Set forking.url in the Hardhat Network config to an archive node RPC. Hardhat replays state from a specific block, letting you test against real contracts.

Q: Is Hardhat free? A: Yes. Hardhat is open-source and free. Nomic Foundation offers optional paid services but the core tool has no cost.

Q: How do I verify contracts on Etherscan? A: Install @nomicfoundation/hardhat-verify and run npx hardhat verify --network mainnet <address> <constructor-args>.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产