> BLACK FRIDAY 70% OFF! Limited Time Offer

April 28, 2022

Foundry Vs Hardhat

Foundry Vs Hardhat image

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.

Main Differences:

Diff #1: Compile Time

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.

Diff #2: Testing Language

Tests in Hardhat are mainly written in Javascript/Typescript, but in Foundry, they are written in Solidity.
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.

Diff #3: Dependencies

Hardhat uses npm to manage dependencies and Foundry manages dependencies using git submodules by default.

Foundry Features:

Feat #1: Traces

Traces
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.

Feat #2: Fuzz Testing

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.
Fuzz Testing
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.

Share this article
Author
Rahul Ravindran's photo
Rahul Ravindran
0 Comments
Leave a reply