In this article, we will be comparing two smart contract development frameworks. Hardhat, which is the most used framework for developing smart contracts and the most preferred one by devs, and Forge (Foundry), which is a new framework written in Rust.
If you are familiar with dapptools, you will find it easy to use Foundry as Foundry is a reimplementation of dapptools.
For the sake of this article, I created a Github repo which is a version of the lsp-smart-contracts repo but with Foundry instead of Hardhat, to compare a few things and try out the features provided by Foundry.
Foundry provides a faster compile time than Hardhat and a comparison using the lsp-smart-contracts shows that the same contracts took ~39.33s to compile with Hardhat Vs ~26.22s with Foundry.
Some developers hate the fact that they have to master another language (JS) to test their Solidity contracts. Also, when writing Solidity tests there is less context switching between languages which helps to focus and gain more Solidity knowledge. + Running the tests in Solidity is much faster than JS.
Hardhat uses npm to manage dependencies and Foundry manages dependencies using git submodules by default.
Traces allows you to see what happens during a function call, and also show you which functions have been called, with which parameters, and what events have been emitted in a simple and nested way.
You can choose to increase/decrease the verbosity to check more/less traces.
Fuzz testing is a very important thing to do that many developers ignore. While writing tests, probably there are some scenarios that are not fully covered in the tests.
Foundry fuzzer will automatically generate random values for the function you specify, to check for edge cases.
After finding values that will make the function expect differently, Foundry will give you the calldata used to produce the behavior.
Foundry is super powerful but it’s still in an early development phase, users are expecting more from the devs in terms of documentation, tutorials, and features.