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

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

Hardhat provides tools to start a local Ethereum network and test ETH and accounts. It serves as a local server using Node.js and operates as a local blockchain server node.

Hardhat Local Ethereum Network Setup

The following steps are required:


  • Install the Node.js environment.
  • Ensure that Node.js and npm are of valid versions.

First, create a directory using the terminal.

A:\work\blockchain>mkdir helloworld

Change to the 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 the Hardhat npm dependency.

A:\work\blockchain\helloworld>npm install --save-dev hardhat
npm WARN deprecated [email protected]: Deprecated in favor of '@metamask/eth-sig-util'
npm WARN deprecated [email protected]: 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 the npx hardhat command to create a Hardhat application. Select the Create a basic sample project option and choose 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 following dependencies:

  • hardhat-waffle: used to build and test smart contracts in a Hardhat environment.
  • ethereum-waffle: provides an API to interact with the Ethereum blockchain.
  • chai: 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 [email protected]: ganache-core is now ganache; visit for details
npm WARN deprecated [email protected]: ganache-core is now ganache; visit for details
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: testrpc has been renamed to ganache-cli, please use this package from now on.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is
npm WARN deprecated [email protected]: request has been deprecated, see
npm WARN deprecated @ensdomains/[email protected]: Please use @ensdomains/ens-contracts
npm WARN deprecated @ensdomains/[email protected]: 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.

Generate Ethereum user addresses and test data in a fake Ethereum environment using npx hardhat accounts

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

Compile Solidity code by download & running npx hardhat compile command.

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

Finally, deploy the default contract by running npx hardhat test:

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)

This should successfully deploy the default contract.