How to setup local Ethereum blockchain using hardhat for build and deploy smart contract

Hardhat is a development environment that provides compiles, deploys, and tests smart contracts in the Ethereum blockchain.

Hardhat provides to start local Ethereum network, test ETH and accounts

It is a local server with Nodejs and it is a local blockchain server node.

Hardhat local Ethereum network setup

The following are steps required


Install nodejs environment Node and npm should give a valid version

First, create a directory using terminal

A:\work\blockchain>mkdir helloworld

Change to directory

A:\work\blockchain>cd helloworld

Create a node application using default settings with the npm init -y command

A:\work\blockchain\helloworld>npm init -y
Wrote to A:\work\blockchain\helloworld\package.json:

  "name": "helloworld",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "keywords": [],
  "author": "",
  "license": "ISC"

Next, Install hardhat npm dependency

A:\work\blockchain\helloworld>npm install --save-dev hardhat
npm WARN deprecated eth-sig-util@2.5.4: Deprecated in favor of '@metamask/eth-sig-util'
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment

added 335 packages, and audited 336 packages in 1m

61 packages are looking for funding
  run `npm fund` for details

9 moderate severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit for details.

Run npx hardhat command to create a hardhat application and select the Create a basic sample project option and select all default options

A:\work\blockchain\helloworld>npx hardhat
888    888                      888 888               888
888    888                      888 888               888
888    888                      888 888               888
8888888888  8888b.  888d888 .d88888 88888b.   8888b.  888888
888    888     "88b 888P"  d88" 888 888 "88b     "88b 888
888    888 .d888888 888    888  888 888  888 .d888888 888
888    888 888  888 888    Y88b 888 888  888 888  888 Y88b.
888    888 "Y888888 888     "Y88888 888  888 "Y888888  "Y888

Welcome to Hardhat v2.8.3

What do you want to do? · Create a basic sample project
Hardhat project root: · A:\work\blockchain\helloworld
Do you want to add a .gitignore? (Y/n) · y
Help us improve Hardhat with anonymous crash reports & basic usage data? (Y/n) · true

You need to install these dependencies to run the sample project:
  npm install --save-dev "hardhat@^2.8.3" "@nomiclabs/hardhat-waffle@^2.0.0" "ethereum-waffle@^3.0.0" "chai@^4.2.0" "@nomiclabs/hardhat-ethers@^2

Project created
See the file for some example tasks you can run.

Next, install the below dependencies

  • hardhat-waffle uses to build test smart contracts in a hardhat environment
  • Ethereum-waffle: API to interact with Ethereum blockchain
  • chai: It is a Test library for javascript applications
A:\work\blockchain\helloworld>npm install --save-dev "hardhat@^2.8.3" "@nomiclabs/hardhat-waffle@^2.0.0" "ethereum-waffle@^3.0.0" "chai@^4.2.
npm WARN deprecated ganache-core@2.13.2: ganache-core is now ganache; visit for details
npm WARN deprecated ganache-core@2.13.2: ganache-core is now ganache; visit for details
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated testrpc@0.0.1: testrpc has been renamed to ganache-cli, please use this package from now on.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is
npm WARN deprecated request@2.88.2: request has been deprecated, see
npm WARN deprecated @ensdomains/ens@0.4.5: Please use @ensdomains/ens-contracts
npm WARN deprecated @ensdomains/resolver@0.2.4: Please use @ensdomains/ens-contracts

added 1099 packages, and audited 1438 packages in 4m

119 packages are looking for funding
  run `npm fund` for details

56 vulnerabilities (8 low, 21 moderate, 27 high)

To address issues that do not require attention, run:
  npm audit fix

Some issues need review and may require choosing
a different dependency.

Run `npm audit` for details.

Next run, npx hardhat accounts to generate Ethereum user address and it is test data in fake Ethereum environment.

A:\work\blockchain\helloworld>npx hardhat accounts

Run npx hardhat compile for download and compile solidity code

A:\work\blockchain\helloworld> npx hardhat compile
Downloading compiler 0.8.4
Compiling 2 files with 0.8.4
Solidity compilation finished successfully

Then, run npx hardhat test command to deploy the default contract.

A:\work\blockchain\helloworld>npx hardhat test

Deploying a Greeter with greeting: Hello, world!
Changing greeting from 'Hello, world!' to 'Hola, mundo!'
Should return the new greeting once it's changed (1407ms)

  1 passing (1s)