hardhat

Guides writing and running Solidity and TypeScript tests in Hardhat 3 projects.

1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/gitforg/BlockChain-Chain-of-Custody --skill hardhat-gitforg
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hardhat
Source: https://github.com/gitforg/BlockChain-Chain-of-Custody/tree/main/contracts/.agents/skills/hardhat
Command: npx skills add https://github.com/gitforg/BlockChain-Chain-of-Custody --skill hardhat-gitforg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Hardhat 3 introduces a dual test-layer model (Solidity tests and TypeScript tests), a new network connection API, and ESM-only constraints that differ significantly from earlier versions. This Skill provides the correct patterns for writing tests, using cheatcodes, manipulating EVM state, and typechecking against compiled contract ABIs so you avoid common migration and usage mistakes. ## Core Features & Use Cases - Test-layer selection guidance: Decide between Solidity tests (.t.sol files with forge-std assertions and cheatcodes) and TypeScript tests (via network.create()) based on whether off-chain orchestration is needed. - EVM state manipulation: Use forge-std cheatcodes (vm.prank, vm.deal, vm.warp, vm.expectRevert) in Solidity tests and networkHelpers (time control, mining, impersonation, fixtures, snapshots) in TypeScript tests. - Compile-then-typecheck workflow: Run npx hardhat build && npx tsc --noEmit to catch wrong argument types and invalid options before running the test suite. - Use Case: You are adding tests to a Hardhat 3 project using the viem toolbox. This Skill tells you to write unit tests as Solidity test contracts, use network.create() with networkHelpers.loadFixture for integration tests, and load the matching hardhat-toolbox-viem skill for client-specific assertions. ## Quick Start Ask the AI to write a Hardhat 3 test for your smart contract, specifying whether you want a Solidity test with forge-std cheatcodes or a TypeScript test using network.create and networkHelpers.

Frequently Asked Questions about hardhat

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write tests in Hardhat 3?▼

Hardhat 3 supports two test layers: Solidity tests (`.t.sol` files with forge-std assertions and cheatcodes) for contract unit tests, and TypeScript tests using `network.create()` for off-chain orchestration. Run all tests with `hardhat test`, or scope to one layer with `hardhat test solidity`.

Should I use Solidity tests or TypeScript tests in Hardhat?▼

Use Solidity tests by default for unit tests on individual contracts since they run in the EVM with cheatcode access. Choose TypeScript tests only when you need off-chain orchestration like multi-contract interactions, fixture reuse, or external balance assertions.

How do I use cheatcodes like vm.prank in Hardhat 3?▼

Import `Test` from `forge-std/Test.sol` in your Solidity test contract to access the `vm` object. Common cheatcodes include `vm.prank(addr)` for setting msg.sender, `vm.deal` for balances, `vm.warp` for timestamps, and `vm.expectRevert` for revert assertions.

Does Hardhat 3 support CommonJS or only ESM?▼

Hardhat 3 only works with ESM, so top-level `await` is available in TypeScript tests. Each call to `network.create()` produces an isolated blockchain state that can be shared across a file or scoped per test.

Why do my Hardhat TypeScript tests have type errors after changing contracts?▼

Generated contract types are derived from the compiled ABI, so you must recompile before typechecking. Run `npx hardhat build && npx tsc --noEmit` to catch wrong argument types and invalid options before running tests.

How do I speed up Hardhat test setup with fixtures?▼

Use `networkHelpers.loadFixture` with a named function that deploys your contracts. It runs the setup once, snapshots the state, and restores the snapshot on subsequent calls instead of redeploying, which is much faster for large suites.