I started developing solidity with Truffle, then moved to Hardhat, then moved to Foundry, then moved back to Hardhat before eventually settling using both on a regular basis.
In this article I’ll talk about the benefits and disadvantages of Hardhat and Foundry so you can make an informed decision about which framework is better for you.
- Hardhat vs Foundry Video
- The Hardhat Ecosystem
- Introduction To Foundry
- Usability & Complexity
- A Performance Comparison
- A Feature Comparison
- Building vs Auditing
- Installing Hardhat & Foundry Together
- Concluding Thoughts Hardhat vs Foundry
Hardhat vs Foundry Video Summary
The Hardhat Ecosystem
Hardhat is a powerful, flexible and extensible framework, designed to make the development process of Ethereum smart contracts as seamless and efficient as possible. It is built and managed by the Nomic Foundation as open source code.
npm install hardhat npx hardhat init npx hardhat test
There are a range of 3rd party plugins and extensions so developers can customize Hardhat to better suit their specific needs, such as integrating with Ethereum libraries and tools.
Hardhat docs: https://hardhat.org/docs
Introduction To Foundry
Foundry is an open-source framework built and maintained by Paradigm.
Foundry runs on Rust and offers various tools to develop and test Solidity smart contracts
- forge – a testing framework for writing unit tests in Solidity
- cast – a command line tool for constructing transaction and executing on-chain functions
- anvil – a local EVM node used for testing
- chisel – a Solidity REPL (Read, Evaluate, Print, & Loop)
Foundry manages dependencies via direct imports from Github with forge install @author/repo
curl -L https://foundry.paradigm.xyz | bash foundryup
In my experience Foundry runs better on Unix based operating systems so if you are using Windows I would recommend installing Windows Subsystem For Linux.
Usability & Complexity
Foundry is marketed as “the framework for pros” which is maybe semi-true in that it does include more tools for sophisticated smart contract analysis.
I wouldn’t be fooled into thinking that it is more professional software however. The naming conventions are quirky at best and it has the feel of a personal project rather than a professional framework developed by a professional team.
Hardhat is more what you’d expect in that department and I tend to find it more intuitive to use. A lot of the time you are working within an ethers.js environment so if you are a full stack developer then it will seem very familiar to frontend code.
Foundry tests are written in Solidity which keeps the testing and code in the same language which I like a lot.
With both tools you’ll need to get familiar with using the command line.
A Performance Comparison
Foundry excels at performance executing tests and scripts faster than hardhat.
In everyday use this isn’t likely to cause an issue and both scripts will run a standard set of unit tests in seconds.
However the improved performance allows foundry to integrate additional capabilities such as native fuzz testing of function inputs. This means that it will send various different inputs to a function to test it can handle min values, zero values, max values, various other data that might cause errors, edge cases and highlight bugs in the code.
A Feature Comparison
Here are some of the unique features of both frameworks
|Extensive plugin and dependencies ecosystem via npm||Fuzz Testing Function Inputs|
|console.log() debugging within solidity code||Traces which are similar to Tenderly transaction debugger breakdowns|
|Superior deployment scripting||Cast command line transaction client|
|Cheatcodes for manipulating state during tests|
For full stack developers that are going to be writing frontend code Hardhat is very intuitive and useful for writing unit tests in the same code. In the past I’ve given frontend developers the unit test files so they can see how all the smart contract functions work and just copy and paste the JS code into their frontend.
If you love Rust and low level languages then Foundry is a better option. The ability to write tests in Solidity and execute them in a minimalist, fast environment is going to be appealing.
Building vs Auditing
I might be biased because of how I’ve ended up using both frameworks but I feel that Hardhat might be more suited towards Solidity developers who are building on Ethereum, while Foundry might be more suited towards smart contract auditors and security specialists.
What I tend to use Hardhat for is writing initial unit tests and deployment scripts. I find Foundry is good for is poking and prodding at my own smart contracts to create “scenario tests” and fuzz inputs.
There’s no reason (with some careful remapping) you can’t use both in the same repository when creating production code. Sometimes having a different toolset can help you look at a smart contract through a different lens and identify issues that weren’t picked up on standard function unit tests.
Installing Hardhat & Foundry Together
There are many Hardhat/Foundry boilerplates, I use my own minimalist one which is available here: SolidStart
Fork or download the SolidStart.js file, (make sure you have NodeJS and Rust installed) and then run:
This will install all the following in one go:
- Foundry (forge, cast, anvil, chisel)
- OpenZeppelin Libraries
- DotEnv for credentials
Concluding Thoughts Hardhat vs Foundry
My general advice is to start with Remix at https://remix.ethereum.org
Use this for proof of concepts and deploying simple tokens etc.
Then use Hardhat (unless you hate Javsacript) for writing unit tests and a deployment script. For testing and deployment I find Hardhat more intuitive and the performance speed has never caused an issue. I can write unit tests faster in Hardhat which more than makes up for shaving a couple of seconds of the test execution time.
Then if you are working on something that is going into a production environment and is security critical. Take some time to do an “internal audit” on your own code using foundry. Foundry is a very powerful tool that has a lot of features well suited to security focused work.