hardhat
Installation
SKILL.md
Hardhat
Hardhat is the dominant Solidity development framework. It provides compilation, testing, deployment, and debugging for EVM smart contracts. The core value is Hardhat Network — a local EVM that supports console.log, stack traces, and mainnet forking. All configuration lives in hardhat.config.ts.
What You Probably Got Wrong
LLMs frequently generate Hardhat code mixing v1 patterns, ethers v5 syntax, and deprecated plugins. These corrections are non-negotiable.
- ethers v6, not v5 — the API changed fundamentally — Hardhat toolbox now bundles ethers v6.
ethers.getContractFactory()returns a different type.parseEther()is a standalone import, notethers.utils.parseEther().BigNumberis gone — ethers v6 uses nativebigint. If you seeBigNumber.from()orethers.utils.*, you are writing v5 code. Stop. hardhat-deployis NOT the official deployment tool — The official deployment system is Hardhat Ignition (@nomicfoundation/hardhat-ignition).hardhat-deployby wighawag is a community plugin that is not maintained by the Hardhat team. Use Ignition for new projects.@nomicfoundation/hardhat-toolboxreplaces individual plugins — Do not install@nomiclabs/hardhat-ethers,@nomiclabs/hardhat-waffle, orhardhat-gas-reporterindividually. Thehardhat-toolboxmeta-plugin includes ethers, chai matchers, coverage, gas reporter, and typechain. The old@nomiclabs/scoped packages are deprecated.npx hardhat compiledoes NOT generate TypeScript types by default — You must have@nomicfoundation/hardhat-toolbox(or@typechain/hardhat) installed AND runnpx hardhat compileto generate types intypechain-types/. The types are not checked into source control.hardhat.config.tsis NOT optional for TypeScript — If you use.tsconfig, you must havets-nodeandtypescriptinstalled. Hardhat uses ts-node to transpile the config at runtime. Without it, Hardhat silently falls back to looking for.js.ethers.getSigners()returnsHardhatEthersSigner, not raw ethers Signer — The signer type isHardhatEthersSignerwhich extends ethersAbstractSigner. It has additional properties like.addressas a direct property (not a method). Type your test variables accordingly.- Hardhat Network resets between test files, not between
it()blocks — State persists acrossit()blocks within the samedescribe(). UseloadFixture()from@nomicfoundation/hardhat-toolbox/network-helpersto get clean state per test. Do not rely onbeforeEachdeploying fresh contracts — it is slower and error-prone. - Forking requires an archive node RPC —
hardhat_resetandforking.blockNumberrequire archive data. Standard RPC endpoints only serve recent state. Use Alchemy or Infura archive tier, or a local archive node. console.login Solidity only works on Hardhat Network —import "hardhat/console.sol"is a Hardhat-specific feature. It does nothing on mainnet, testnets, or other local nodes. Do not leaveconsole.login production contracts — it wastes gas on the import.- Constructor arguments for verification must match exactly —
npx hardhat verifyfails silently when constructor args do not match the deployed bytecode. Use the--constructor-argsflag pointing to a JS file that exports the exact arguments used during deployment.