Hardhat: An Ethereum Development Environment
A brief breakdown the features I like about the increasingly popular Ethereum development environment, Hardhat
The previous technical newsletters have focused specifically on the Solidity language, but there is more to blockchain development than just the language itself. When you are comfortable with the language it is time to move on to selecting a development environment that will allow you to test and deploy smart contracts.
Development environments are a collection of procedures and tools for developing, testing and dubgging an application or program - techopedia.com
You can think of a development environment like a factory that contains tools to piece together the individual parts (Solidity smart contracts) of a car and then ship it off to run on the road (blockchain). There are multiple Ethereum development environments available today like Truffle (The OG), Hardhat (making a buzz) and scaffold-eth (All-in-one). I encourage you to take a look at the Ethereum development tools page to compare and determine which tool is suitable for you, but for the sake of simplicity and personal preference, I will be using Hardhat. Rather than listing out my reasons, I will link to the newsletter that summarizes how I landed on using Hardhat.
Getting started with Hardhat requires node.js and npm to be installed on your computer. For those new to engineering, I would recommend installing nvm to install both, which is a version management tool that allows you to switch between node versions and includes npm. This is a much simpler tool than installing and maintaining individual versions of node.js and npm separately.
Once you have these languages installed on your computer, you will be able to follow the Hardhat tutorial to install local Hardhat projects and get started with your Solidity project. Rather than regurgitate the Hardhat setup, which is well defined on their website, I will highlight some of the great features of using Hardhat when building, testing, and deploying your Solidity project to the blockchain.
Plugins
Plugins are a feature that is becoming more common among the development environments, but I think what is unique about Hardhat is that its architecture and infrastructure are built around this composability. They aren’t looking for vendor lock-in and even provide documentation on how you can interact with other 3rd party tools like Truffle’s node environment or Web3.js. Hardhat provides the boilerplate and allows you to build and change whatever you like. No other environment at the moment has this level of flexibility for developers.
Console Logging
Since we are still in the early stages of the Solidity language, there should be no surprise that there is yet to be feature parity with other mature programming languages. One important feature found in almost every commonly used language that is missing from Solidity today is logging. The simplicity of using console.log to quickly understand the output of our code makes it faster and easier to debug your work and catch issues prior to writing unit tests. While Solidity does not have a built-in console logging feature, Hardhat built out a solidity contract to create logging with the same syntax as you would use with JavaScript. I have found this feature extremely helpful in speeding up the time it takes to build a contract and run test transactions.
Testing
Hardhat comes pre-configured with Mocha and Waffle for testing. The advantage of having both test frameworks enabled by default is that you can test both your smart contracts and Javascript interactions without having to download additional libraries. This suite of testing tools takes care of both front-end code and contract coverage.
CLI and Tasks
Like other Solidity development environments, the CLI is a core component to run test EVM nodes and deploy your contracts. What is unique about Hardhat’s CLI is the ability to add tasks to extend the automation capabilities the CLI provides. A task is a JavaScript async function that contains metadata. This metadata is what Hardhat transcribes and uses when a task is triggered.
Ethers.js
So far my newsletter has focused on Solidity and raw deployment/interaction with smart contracts, but what if we wanted to interact with these contracts within a web application? This is where Ethers.js, comes in handy as it is a front-end library that creates a gateway between the browser and the Ethereum blockchain. This library is crucial to create Dapps that allow users to connect and interact with an application via their wallet.
Support
There is a great Discord community that connects you with other users of Hardhat, as well as the creators and maintainers of the open-source software. Outside of Github issues, I can’t think of a better place to get real-time support for your Hardhat issues. In the few instances I have surfaced problems I was facing with my own development, multiple members of the community responded to help out!