https://github.com/chainstacklabs/foundry-vs-hardhat
Comparing Foundry and Hardhat in performance and the developer experience
https://github.com/chainstacklabs/foundry-vs-hardhat
foundry hardhat smart-contracts
Last synced: 24 days ago
JSON representation
Comparing Foundry and Hardhat in performance and the developer experience
- Host: GitHub
- URL: https://github.com/chainstacklabs/foundry-vs-hardhat
- Owner: chainstacklabs
- Created: 2022-03-11T14:49:05.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T14:31:46.000Z (almost 2 years ago)
- Last Synced: 2025-07-18T07:01:37.563Z (9 months ago)
- Topics: foundry, hardhat, smart-contracts
- Language: Solidity
- Homepage: https://chainstack.com/foundry-hardhat-differences-performance/
- Size: 1.95 MB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Hardhat vs Foundry
**[You can read the full article for this project in the Chainstack blog](https://chainstack.com/foundry-hardhat-differences-performance/)**
This repository contains two similar projects built with Hardhat and Foundry.
## Differences
| | Foundry | Hardhat |
| -------------------------- | --------------------------------- | -------------------------------------- |
| Installation | via CLI curl command | not required with NPX, or via NPM |
| CLI tools | **forge** to manage the project (build/compile) & **cast** to interact with smart contracts | **hardhat** manage the project (build/compile/run scripts) |
| Build & test performance | 💨💨💨💨💨 | 🐢🐢 |
| Configuration file | `foundry.toml` | `hardhat.config.js` |
| Allows project folder configuration | Yes, in `foundry.toml` file | Yes, in `hardhat.config.js` file |
| Dependency management | GitHub submodules (any repository) | NPM packages |
| Dependencies file | .gitmodules | package.json | | |
| Files included in sample project | empty smart contract and basic test | Greeter smart contract (with set/get methods), test files and script to run locally |
| Test file format | Solidity contracts | JavaScript test files |
| Test assertion library (default) | ds-test | Mocha |
| Allows to alter blockchain status (time, block) in tests | Yes via cheatcodes | Limited, via mainnet forking. |
| Allows run specific tests? | Yes via --match-test --match-contract | Yes via "only" or "skip" in test files |
| Contract deployments | Via forge CLI or Bash scripts (new solutions in progress) | Via JS scripts |
| Blockchain / contracts interaction | via Cast CLI tool | N/A |
## Default project structure vs Hardhat
| Files | Foundry | Hardhat |
| -------------- | --------- | ------------- |
| Contract files | /src | /contracts |
| Test files | /src/test | /test |
| Output | /out | /artifacts |
| Dependencies | /lib | /node_modules |
## Testing with Foundry
| Pros | Cons | Neither |
| ------------------------- | --------------------------------------------------------------------------- | ------------------------ |
| No async/await | Test names not as descriptive as in JS tests | tests writen in solidity |
| Tests require less code | Cheats are difficult to understand at first |
| Tests run super fast | `expectRevert` assertion is weird |
| Auto-generated gas report | `testFail` only tests if the test fails, not if the error is what we expect |