Foundry vs Hardhat
Rust-based tooling.
Foundry vs Hardhat is a free Web3 & DApp Development Fundamentals lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web3 & DApp Development Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Foundry
Foundry is a fast, Rust-based toolkit for Ethereum development. It lets you write tests, scripts, and deployments entirely in Solidity, with no JavaScript layer required.
Its speed and Solidity-native testing have made it the dominant choice for many professional smart contract teams.
The Four Tools
Foundry ships as four command-line tools:
- forge — build, test, and deploy contracts
- cast — interact with chains and contracts from the CLI
- anvil — a local development blockchain
- chisel — a Solidity REPL
Together they cover the full development lifecycle.
What Is Hardhat
Hardhat is a JavaScript and TypeScript based development environment. Tests and scripts are written in JS/TS using libraries like ethers.js or viem, and it has a rich plugin ecosystem.
It is well suited to teams comfortable in the Node.js world and projects with heavy off-chain tooling.
Language for Tests
The biggest difference is the testing language:
- Foundry — tests are Solidity contracts; no context switch from your contract code
- Hardhat — tests are JavaScript/TypeScript using a chai-style assertion library
Solidity tests give Foundry direct access to internal state and low-level cheatcodes.
// Foundry test (Solidity)
function testIncrement() public {
counter.increment();
assertEq(counter.number(), 1);
}Speed
Foundry's Rust implementation and native EVM make it dramatically faster than Hardhat's Node-based runner, often by an order of magnitude on large suites.
Fast feedback loops matter: when tests run in milliseconds, developers run them constantly, catching bugs earlier.
Project Layout
A Foundry project has a conventional structure:
src/— your contractstest/— Solidity test files (suffix.t.sol)script/— deployment scripts (suffix.s.sol)lib/— dependencies installed as git submodulesfoundry.toml— configuration
myproject/
src/Counter.sol
test/Counter.t.sol
script/Deploy.s.sol
lib/forge-std/
foundry.tomlDependency Management
Foundry installs dependencies as git submodules via forge install, with import remappings instead of an npm registry. Hardhat uses npm packages.
Submodules keep exact source pinned in your repo, while npm offers familiar versioning and a vast package ecosystem.
$ forge install OpenZeppelin/openzeppelin-contracts
# adds to lib/ and updates remappingsCheatcodes
Foundry's killer feature is cheatcodes: special calls via the vm object that manipulate EVM state in tests. You can warp time, set balances, impersonate addresses, and expect reverts.
Hardhat offers similar capabilities through helper plugins, but Foundry's are built in and accessible directly from Solidity.
vm.warp(block.timestamp + 1 days);
vm.prank(alice);
vm.expectRevert("not owner");Scripting and Deployment
Foundry deployments are Solidity scripts run with forge script, using vm.startBroadcast() to send real transactions. Hardhat deployments are JS scripts run with hardhat run.
Solidity scripting keeps deployment logic in the same language as the contracts, reducing context switching.
function run() external {
vm.startBroadcast();
new Counter();
vm.stopBroadcast();
}Choosing Between Them
There is no universal winner:
- Choose Foundry for speed, fuzzing, and Solidity-native testing
- Choose Hardhat for rich JS/TS tooling and a large plugin ecosystem
Many teams use both: Foundry for unit and fuzz tests, Hardhat for complex deployment and integration tasks. They can coexist in one repo.
Installing Foundry
Foundry installs via foundryup, a version manager that fetches the latest binaries. Once installed, forge init scaffolds a new project ready to build and test.
$ curl -L https://foundry.paradigm.xyz | bash
$ foundryup
$ forge init my_projectQuick Check
In what language are Foundry tests written?
Recap
You compared the two main toolkits:
- Foundry is Rust-based with Solidity tests; Hardhat is Node-based with JS/TS tests
- Foundry tools: forge, cast, anvil, chisel
- Foundry is faster and has built-in cheatcodes and fuzzing
- Dependencies via git submodules vs npm
Next we dive into writing tests with forge.
Frequently asked questions
Is the “Foundry vs Hardhat” lesson free?
Yes — the full text of “Foundry vs Hardhat” is free to read here on the web, and the Web3 & DApp Development Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web3 & DApp Development Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Foundry vs Hardhat”?
Rust-based tooling. You practise Web3 & DApp Development Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Web3 & DApp Development Fundamentals?
No prior experience is required. Web3 & DApp Development Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Foundry vs Hardhat” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Web3 & DApp Development Fundamentals lesson?
Yes. Every Web3 & DApp Development Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Foundry vs Hardhat
- forge Testing
- Fuzzing and Invariants
- cast and anvil