Hardhat is a development environment to compile, deploy, test, and debug your dApps. It helps developers manage and automate the recurring tasks that are inherent to the process of building smart contracts and dApps, as well as easily introducing more functionality around this workflow. This means compiling, running, and testing smart contracts at the very core.Hardhat comes built-in with Hardhat Network, a local Ethereum network designed for development. It functionality focuses around Solidity debugging, featuring stack traces, console.log(), and explicit error messages when transactions fail. Learn more from here.
Create an empty hardhat.config.js. Now, let’s configure the file.
hardhat.config.jsfile to assign the Solidity version and RPC server. In my case I use Visual Studio Code.
private.json, where we store the private key. Never reveal your private key. The private.json looks like this:
HelloWorld.solfile, and be sure to read the comments to understand what this contract does:
HelloWorld.sol, uses Solidity 0.8.1. Make sure the Hardhat configuration file (
hardhat.config.js) is correctly set up with this solidity version. When everything meets the criteria, we can compile the contract by running:
deploy.js, adding the following contents to it:
ethers.jsis an abstraction used to deploy new smart contracts, so HelloWorld here is a factory for instances of our
hello worldcontract. When using the
hardhat-ethersplugin ContractFactory and Contract instances are connected to the first signer by default.
deploy( )on a
ContractFactorywill start the deployment, and return a
Promisethat resolves to a
Contract. This is the object that has a method for each of our smart contract functions.
HelloWorldcontract to Dusty: