Foundry Vs Hardhat
Tags: solidity, ethereum, hardhat, foundry
Published: 2022-04-11 14:40:26


![Foundry Vs Hardhat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdf4zqp3u722x7vjv3ec.png)

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](https://github.com/YamenMerhi/foundry-lsp-smart-contracts) which is a version of the [lsp-smart-contracts](https://github.com/lukso-network/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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nw0zkh14wliusjxmya4x.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61wdnc56aljrhy24mqn5.png)
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.

> End of the article.
> Connect with me on [LinkedIn](https://www.linkedin.com/in/yamenmerhi/), [Github](https://github.com/YamenMerhi), and [Twitter](https://twitter.com/0xYamen).

### References :

1. https://www.youtube.com/watch?v=Rp_V7bYiTCM&t=1119s
2. https://book.getfoundry.sh/index.html
3. https://www.paradigm.xyz/2021/12/introducing-the-foundry-ethereum-development-toolbox