dev-tooling/hardhat-vs-foundry
Hardhat vs Foundry Selection Guide
ethereumdev-tools👥 Communityconfidence highhealth -2%
v1.0.0·Updated 3/20/2026
Core Differences at a Glance
| Dimension | Hardhat | Foundry |
|---|---|---|
| Language | JavaScript/TypeScript | Rust + Solidity tests |
| Testing Approach | Write tests in JS (ethers/viem) | Write tests in Solidity (forge-std) |
| Speed | Slower (JS runtime) | Extremely fast (Rust compiled, concurrent execution) |
| Fuzz Testing | Requires plugins | Built-in, enable in one line |
| Debugging | console.log, can fork mainnet | forge debug, trace level |
| Plugin Ecosystem | Mature (hardhat-deploy/upgrades) | Growing |
| Learning Curve | Low (just need JS) | Medium (need to understand Solidity testing) |
| Deployment Scripts | JS/TS scripts | Solidity Script (forge script) |
| Community | Larger, more comprehensive docs | Rapidly growing, Paradigm-led |
Scenarios for Choosing Foundry
# Quick installation
curl -L https://foundry.paradigm.xyz | bash && foundryup
# Create new project
forge init my-project && cd my-project
# Testing (10-100x faster than Hardhat)
forge test
forge test -vvv
forge test --match-test testFuzz
# Fuzz testing: functions accepting parameters automatically fuzz
# function testFuzz_transfer(uint256 amount) public { ... }
# Fork mainnet testing
forge test --fork-url https://eth-mainnet.alchemyapi.io/v2/KEY
# Gas reports
forge test --gas-report
Choose Foundry if:
- Pure contract project with no complex frontend integration
- Need extensive fuzz/invariant testing
- Care about CI time (test speed)
- Team is proficient in Solidity
Scenarios for Choosing Hardhat
npm install --save-dev hardhat && npx hardhat init
# hardhat-deploy (recommended)
npm install --save-dev hardhat-deploy
# OZ Upgrades plugin
npm install @openzeppelin/hardhat-upgrades
Choose Hardhat if:
- Full-stack project, frontend needs artifacts/typechain
- Using hardhat-deploy for complex deployment workflows
- Need OpenZeppelin Upgrades plugin
- Team has JS/TS background
Hybrid Approach (Best Practice for Mature Projects)
Many protocols use both: Foundry for unit/fuzz tests (speed), Hardhat for deployment scripts (rich ecosystem).
my-project/
├── foundry.toml # Foundry config
├── hardhat.config.ts # Hardhat config
├── src/ # Contracts (shared)
├── test/ # Foundry tests (.t.sol)
└── scripts/ # Hardhat deployment scripts (.ts)
Quick Command Reference
# Foundry
forge build && forge test
forge script Deploy.s.sol --rpc-url $RPC --broadcast
cast call $ADDR "balanceOf(address)(uint256)" $USER
cast send $ADDR "transfer(address,uint256)" $TO $AMT --private-key $KEY
# Hardhat
npx hardhat compile && npx hardhat test
npx hardhat run scripts/deploy.ts --network mainnet
npx hardhat verify --network mainnet $ADDR