DEV Community

Pari Tomar for BuildBear

Posted on • Updated on

Hardhat or Truffle? As a beginner blockchain developer, which one do I pick

Image description

In a blockchain developer’s life, one of the major pain point is to find the best-suited framework or tool for him/her. People spend days or weeks finding the right tool for them.

Similarly, in the Blockchain world, one of the major debate is on choosing between Hardhat or Truffle.

These development environments help developers to manage many of the tasks that are inherent to developing decentralized applications and smart contracts.

If you just starting out your career in the blockchain world and, just like us, albeit sometime back, are wondering which one to choose: Hardhat or Truffle, then you’re at the right place!! 🥳🥳  In the below paragraphs, we have discussed both these frameworks and have proceeded further to do a small comparison of sorts.

Hardhat Tool

Image description

Hardhat is an Ethereum development environment for developers that allows performing frequent tasks.

Other than just deploying and running tests, Hardhat also provides some more features that make it more powerful and unique.

Let's consider these features one by one.

  • Hardhat Network

Hardhat comes built-in with Hardhat Network, a local Ethereum network node designed for development providing multiple features like automated error messages, mainnet forking, and, mining modes.

So if you’re using Hardhat, then by default you’re already using Hardhat Network. It mines a block with each transaction that it receives, in order and with no delay.

  • Plugins

Next up is Plugins.

Plugins, in simpler words, are extensions that can be loaded on a program to improve its functionality.

There are 30+ plugins used in development with Hardhat which is why it is considered the backbone of Hardhat.

We have listed some of the popular plugins below with their functionalities:

Hardhat provides a very simple procedure for testing smart contracts, providing developers to write automated tests when building smart contracts.

Hardhat provides great documentation for understanding testing methods with Hardhat.

If you’re new to Hardhat Testing, try our previous article to get a better understanding of Hardhat Testing.

The Universe of Truffle Tools

Image description

Like Hardhat, Truffle is also a development environment dedicated to Ethereum blockchain.

Truffle is a highly popular development framework and provides a large community behind the tool.

For decentralized applications development, the developer uses Truffle Suite.

The Truffle Suite is an ecosystem for Web3 development that consists of three different tools: Truffle, Ganache, and Drizzle

Image description

  • Truffle: It is a development environment that uses the EVM for smart contract development.
  • Ganache: Ganache is a tool used to set up your own local Ethereum blockchain that you can use to deploy and test your smart contracts.

Other than that, Ganache enables developers to avoid paying unnecessary gas fees during the developing process.

  • Drizzle: Drizzle is a collection of frontend libraries with a Redux store as its basis.

With this, the frontend development becomes a lot easier for the developers.

Truffle offers several different features like:

  • Smart Contract Management:

Truffle helps you manage the artifacts of the smart contracts so that you can focus on the other parts of the development process and spend less time on the file organization.

  • Scriptable Migration and Deployment:

With Truffle, you can write deployment scripts that allow you to account for the fact that your Dapps will change over time.

  • Powerful Interactive Console:

Truffle provides 2 different consoles to choose the best tool for your needs.

(A) Truffle Console: A basic interactive console connecting to any Ethereum client. To launch the console, use the truffle console command. When you load the console, you'll immediately see the following prompt:
Image description

Truffle console will let you connect with the contracts deployed on the EVM client and interact with the contracts in a manner similar to the one that you would use through javascript.

(B) Truffle Develop: An interactive console that also spawns a development blockchain. It serves the same purpose as the hardhat node

You can simply launch the Truffle Develop by using the truffle develop command

Image description

  • Truffle Dashboard:

Recently, Truffle has introduced Truffle Dashboard, providing an easier way to use your existing Metamask wallet for your deployments and transactions. Using Truffle Dashboard is not only easy but is a plug and play. You can use the Truffle Dashboard inside any Hardhat projects also. Truffle has provided great documentation to follow along and use Truffle Dashboard in your project.

Which one is more powerful?

Let us compare some of their features and get a final answer to our question!! 💪

1. Debugging

Solidity is hard to debug. You just get an error message when something breaks and more often than not, it is painful to debug what exactly went wrong.

Thankfully, Hardhat introduced something known as the console.log feature for Solidity.

So you can simply import the console plugin and can use it inside your functions.

This is what it looks like:

Image description

Add some console.log inside the function

Image description

The logging output will show when you run your tests:

Image description

The EVM created by hardhat specifically supports this feature and hence is native to Hardhat Node. This feature alone is a heavy pro for Hardhat.

On the other hand, Truffle has been improving its debugger and it also has some plugins for it but Hardhat is considered a more easier and powerful tool used for debugging.

2. Libraries (Ethers and Web3)

Hardhat uses ethersjs by default but can be easily modified to use Web3. Whereas, Truffle uses Web3 as default plugin for development.

You can also use Etherjs with Truffle but it is considered to be trickier and hard to implement.

While ethers-js and web3-js are similar, there is a very high uptick in the number of developers using ethers-js as default; this should presumably give you some hint on what you could / should consider for developing.

3. Local Ethereum Network node

Hardhat comes inbuilt with Hardhat Node. However, it does not have a GUI for developers to see account info in real-time.

Truffle, on the other hand, uses Ganache which has to be set up separately. However, it comes with both a CLI and a GUI version allowing flexibility for the developer.

If you prefer the GUI you should choose Ganache.

4. Deployment

For deploying a contract, Hardhat uses basic javascript scripts to deploy, so it’s easier to get started with it and is relatively simple to use.

Whereas, Truffle uses a migration-based deployment procedure (which are js files themselves, but have a sequential order of execution) which is a bit more complicated for a beginner, but can be helpful in the long term keeping in mind that your deployment needs might change in the future.

But for ease of getting started with deployment, hardhat definitely takes the prize.

5. Testing

To perform various tests, both Truffle and Hardhat use the Chai assertion library and Mocha as their testing framework but hardhat also includes waffle. They’re both strong when it comes to testing.

6. Statistics

Before Hardhat was launched, Web3 was the most popular framework for testing out smart contracts.

Later on, now you can see that the trend changes over time, and Hardhat has gained more popularity as compared Truffle.

According to the NPMJS Statistics, Truffle has almost 30k weekly downloads. Whereas, Hardhat has around 86k weekly downloads, which is twice as compared Truffle’s.

Image description

7. Community

Truffle’s Github community is quite active and helpful, whereas Hardhat provides a Discord server for their community support. It must be noted that the entire Truffle offering is supported by Consensys and hence you can expect a “support helpdesk” treatment. Hardhat too is developed and managed through an organization: the Nomic Foundation and has an amazing and equally good support system through its discord server.

Conclusion

It is really hard to say which is the best. The choice of Truffle vs Hardhat comes down to one’s own preferences and use cases, as they both are two powerful tools.

If you’re absolutely new to both frameworks, then you should definitely explore both of them and decide which one is the best for ‘you’.

However, we hope this article was able to give you an insight into the differences between them and was able to help you to find which one to use.

Tell us which framework do you prefer over the other by tagging us on Twitter at @uv_labs

Give us a clap if you liked our work.

Authors (open to feedback): 👇

Pari Tomar, Mayon Francis and Amateur-Dev

Top comments (0)