Foundry Vs Hardhat

Rahul Ravindran

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.

0 Comments

Leave a Reply

More great articles

Creating a new Contract from another Contract in Solidity

Introduction In blockchain development, mining sets of data into a blockchain is quite an expensive process because fees are charged…

Read Story

Solidity Security Part 1 – Reentrancy Attack

One of the major dangers of calling external contracts is that they can take over the control flow, and make…

Read Story

Polygon Explained: How Polygon is Leading Scaling Solutions for Ethereum

Previously known as Matic Network, Polygon is a framework for building interconnected blockchain networks. It seeks to address some of…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up