Pick Foundry if your contracts are the product and your team is comfortable writing tests in Solidity. Pick Hardhat if your tests need to share code with a TypeScript frontend or backend. Hardhat 3 can also run Solidity tests with fuzzing, so the choice is no longer all or nothing.
I tested the same small contract in both tools on one machine. The numbers are below, with the method, so you can repeat them.
Short answer by team type
| Your team | Start with | Why |
|---|---|---|
| Solidity-heavy, few JS developers | Foundry | Fast runs, fuzzing and invariants built in, no JS toolchain |
| Full-stack team, TypeScript everywhere | Hardhat 3 | Same language and types as the frontend, ethers v6 in tests |
| DeFi protocol with complex state | Foundry | Invariant testing and cheatcodes are first class |
| Dapp with simple contracts, big UI | Hardhat 3 | Contract and UI tests live in one toolchain |
| Not sure | Both | They coexist in one repo, see the last section |
Comparison table
State of the tools when I wrote this (November 2026): Hardhat 3.21.2, Foundry 1.5.1 (forge), ethers 6.17, Solidity 0.8.28.
| Foundry | Hardhat 3 | |
|---|---|---|
| Test language | Solidity | TypeScript (Mocha or node:test), plus Solidity tests |
| Fuzzing | Built in, testFuzz_ functions |
Fuzz tests in Solidity; JS tests need a library |
| Invariant testing | Built in | Not in the Solidity testing guide I read, so check before relying on it |
| Mainnet forking | --fork-url, vm.createSelectFork |
Forking a network in config, createSelectFork cheatcode in Solidity tests |
| Debugging | Traces with -vvvv, forge debug |
Stack traces, console.log in Solidity |
| Frontend integration | ABIs in out/, needs a bridge to JS |
Same repo, same language, ethers or viem |
| Install | One binary | Node project with plugins |
I only listed what I could confirm in the docs. Check the Foundry book and the Hardhat docs for your version before you commit, since both move fast.
The same test, in both
The contract is a small ETH vault. It has a deposit, a withdraw, two events and custom errors.
contract Vault {
mapping(address => uint256) public balanceOf;
event Deposited(address indexed account, uint256 amount);
event Withdrawn(address indexed account, uint256 amount);
error InsufficientBalance(uint256 requested, uint256 available);
error ZeroAmount();
error TransferFailed();
function deposit() external payable {
if (msg.value == 0) revert ZeroAmount();
balanceOf[msg.sender] += msg.value;
emit Deposited(msg.sender, msg.value);
}
function withdraw(uint256 amount) external {
uint256 available = balanceOf[msg.sender];
if (amount > available) revert InsufficientBalance(amount, available);
balanceOf[msg.sender] = available - amount;
emit Withdrawn(msg.sender, amount);
(bool ok, ) = msg.sender.call{value: amount}("");
if (!ok) revert TransferFailed();
}
}
Here is the revert test for withdrawing too much, in Foundry:
function test_RevertsWhenWithdrawingMoreThanBalance() public {
vm.startPrank(alice);
vault.deposit{value: 1}();
vm.expectRevert(abi.encodeWithSelector(Vault.InsufficientBalance.selector, 2, 1));
vault.withdraw(2);
vm.stopPrank();
}
And in Hardhat 3 with ethers v6 and Mocha:
import { expect } from "chai";
import { network } from "hardhat";
const { ethers } = await network.create();
it("reverts when withdrawing more than the balance", async () => {
const [alice] = await ethers.getSigners();
const vault = await ethers.deployContract("Vault");
await vault.connect(alice).deposit({ value: 1n });
await expect(vault.connect(alice).withdraw(2n))
.to.be.revertedWithCustomError(vault, "InsufficientBalance")
.withArgs(2n, 1n);
});
The Hardhat version reads closer to the chai matchers a JS tester already knows. The Foundry version has no imports of a chain client, no await, and the setup is plain Solidity. Neither is harder. Which one feels natural depends on what your team writes all day.
My Hardhat config is short:
import { defineConfig } from "hardhat/config";
import hardhatToolboxMochaEthers from "@nomicfoundation/hardhat-toolbox-mocha-ethers";
export default defineConfig({
plugins: [hardhatToolboxMochaEthers],
solidity: "0.8.28",
});
Hardhat 3 changed this file from version 2. Plugins are listed in the config instead of imported for side effects, and network.create() replaces the global ethers import. If you follow an older tutorial, expect to adjust. Our own integration testing post shows an older Hardhat setup, so treat its config lines as version 2.
Speed in CI
I ran five equivalent tests, then 500 copies of one test to see how each tool scales. Machine: Apple M3 Max, local, nothing else running. Each number is the wall time of the full command, three runs each, rounded.
| Run | Foundry (forge test) |
Hardhat 3 (hardhat test) |
|---|---|---|
| 5 tests, compiled already | 0.20 s | 0.57 s |
| 5 tests, clean build | 0.96 s | 0.57 s |
| 500 tests, compiled already | 0.20 s | about 1.5 s |
Read this carefully. The clean-build row favours Hardhat only because Foundry compiled forge-std as well, 21 files against one. The 500-test row is synthetic: the same tiny test repeated. Real suites have heavier setup, forks and fuzz runs, and they will behave differently. What the numbers do show is a gap in per-test overhead. Foundry runs tests in the Rust-based EVM inside one process with no JavaScript between them, and the gap grows with test count.
Does it matter? On a 30-test suite, no. You will not notice 1 second. It starts to matter when you run fuzz tests with thousands of runs, or a large suite on every pull request. If your CI minutes are paid and your suite has hundreds of tests, the saving is real. Our CI post on parallel tests covers what to do when the suite is still slow after that.
To reproduce: put both projects in separate folders, use /usr/bin/time -p around the command, and run it three times.
Fuzzing and invariants
Foundry fuzzing is a function with arguments:
function testFuzz_DepositThenWithdrawRestoresBalance(uint96 amount, uint96 out) public {
amount = uint96(bound(amount, 1, 100 ether));
out = uint96(bound(out, 0, amount));
vm.startPrank(alice);
vault.deposit{value: amount}();
vault.withdraw(out);
vm.stopPrank();
assertEq(vault.balanceOf(alice), amount - out);
}
That ran 256 times by default in my run, with no extra setup. In a Mocha test you would write the loop and the random generator yourself, or add a property-testing library. That is the strongest practical argument for Foundry: the habit of writing property tests costs nothing, so people do it.
Hardhat 3 closes some of that gap with Solidity tests that use forge-std and the same cheatcodes. If you want fuzzing and Hardhat’s JS tests in one repo, that is possible. For the technique itself, see how to test smart contracts, and for the patterns that go inside either tool, Solidity unit test patterns.
Frontend integration
This is where Hardhat still has the edge. A TypeScript test can import the same types and helpers your frontend uses, deploy contracts, and drive a browser test from the same process. With Foundry you export ABIs from out/ and wire the JS side yourself.
None of this is hard. It is one more build step to maintain. If your plan is dapp end-to-end tests, read integration testing for web3 smart contracts and frontend first. A local Anvil node works for browser tests no matter which framework compiled the contracts.
Which team should pick which
My recommendation, reasoned from the above:
- Contracts are the product, you hold other people’s money. Foundry. Property tests, fuzzing and fast feedback are worth more than JS sharing.
- One small contract set behind a large app. Hardhat 3. One language, one test runner, less to explain to the next hire.
- A mixed team. Foundry for the contract suite, TypeScript for dapp and API tests. Two tools is fine if each owns a layer.
The tools coexist. Both compile plain Solidity files, so you can point each at the same contracts folder. The expensive mistake is not picking the wrong tool. It is picking none and shipping with a handful of happy-path tests.
Your next step
Take one real contract from your repo. Write the revert test and one fuzz test in the tool you lean towards, and run it in CI. If it takes you under an hour, you have your answer. If you fight the setup, try the other. Then keep that one.
FAQ
Is Hardhat dead now that Foundry exists? No. Hardhat 3 is actively developed, ships Solidity test support, and remains the easier path when contracts and TypeScript code live together.
Can I use Foundry and Hardhat in the same repo? Yes. Point both at the same contracts folder and run each in its own CI job. Many teams use Foundry for contract tests and Hardhat for deployment scripts and integration tests.
Is Foundry faster than Hardhat? In my small test, yes: 0.20 seconds against about 1.5 seconds for 500 tests. The gap comes from per-test overhead, so check it on your own suite before you decide on speed alone.
Which one is better for fuzz testing? Foundry, because fuzz tests are ordinary functions with arguments and need no extra libraries. Hardhat 3 supports fuzz tests written in Solidity, not in its JavaScript tests.