In a blockchain developer’s life, one of the major pain points 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 debates 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 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 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.
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:
@nomiclabs/hardhat-ethers: It allows developers to inject ethers.js into the Hardhat Runtime Environment. @nomiclabs/hardhat-waffle: It allows you to add a Waffle-compatible provider to the Hardhat Runtime Environment. @nomiclabs/hardhat-etherscan: It automatically verifies contracts on Etherscan hardhat-gas-reporter: Gas reporter helps to acknowledge the gas usage per unit test and average gas usage per method.
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.
Like Hardhat, Truffle is also a development environment dedicated to the 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
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:
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.
With Truffle, you can write deployment scripts that allow you to account for the fact that your Dapps will change over time.
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:
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
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
Let us compare some of their features and get a final answer to our question!! 💪
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
So you can simply import the console plugin and can use it inside your functions.
This is what it looks like:
Add some console.log
inside the function
The logging output will show when you run your tests:
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.
Hardhat uses ethersjs by default but can be easily modified to use Web3. Whereas, Truffle uses Web3 as the 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.
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.
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.
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.
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 to 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.
Truffle’s
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.
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.
Also Published Here
Tell us which framework do you prefer over the other by tagging us on Twitter at
Give us a clap if you liked our work.
Authors (open to feedback): 👇