Following are steps required to create and setup a hardhat project

  • Setup prerequisite
  • Create a new Brand new Nodejs application
  • Install Hardhat npm dependency
  • Hardhat project directory structure

Prerequisites

The following are required to have before setup a hardhat project.

First, run the below command to know NodeJS is installed or not.

A:\work>node --version
v14.17.0

A:\work>npm --version
7.11.1

It gives node and npm versions if nodejs is installed.

Create a Nodejs project

First, Open a terminal, and create a directory

mkdir hardhatproject

It creates hardhatproject folder Change to hardhatproject folder.

cd hardhatproject

Create a Nodejs Project on a folder with default configuration with running npm init -y.

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

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


npm notice
npm notice New major version of npm available! 7.11.1 -> 8.5.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.5.0
npm notice Run npm install -g [email protected] to update!
npm notice

It creates package.json with default configurations.

Install Hardhat npm dependency

Next, Run hardhat npm dependency using the below command

npm install --save-dev hardhat

It takes some time to installs hardhat dependency and indirect dependencies Ethereum JavaScript dependencies.

with installation, It comes with a hardhat command line to create and manage the project.

Create a hardhat project

Run the below command(npx hardhat) to create a hardhat project

npx hardhat

It displays the following options and the user select one of the options from below

What do you want to do? … Create a basic sample project Create an advanced sample project Create an advanced sample project that uses TypeScript Create an empty hardhat.config.js Quit

And, select the Create a basic sample project option Next it asks for Hardhat project root:, select default Next, select default for Do you want to add a .gitignore? (Y/n) » y

It installs and creates a project with the required folder and files.

Hardhat Folder Directory structure

Here is the project created with a hardhat with a basic sample project.

hardhatproject
        |   .gitignore
        |   hardhat.config.js
        |   package-lock.json
        |   package.json
        |
        +---contracts
        |       Greeter.sol
        +---scripts
        |       sample-script.js
        |
        \---test
                sample-test.js

It contains the following files and folder

  • Contracts: It contains smart contract code written Solidity with file extension .sol. By default, It generates Greeter.sol simple contract hello world example. It also generates ABI and addresses json files generated during compilation and deployment scripts.
  • scripts: It contains javascript code to manage hardhat environment and Ethereum network
  • test: It contains javascript code to write unit testing code for testing the contract.
  • hardhat.config.js: It contains javascript configuration to configure tasks and plugins
  • package-lock.json: It is a file created by a node to have direct and indirect dependencies installed on your project.
  • package.json: Package manager file for nodejs project, that contains dependencies and scripts and meta-information about the project.
  • .gitignore: It contains files and folder paths to be ignored by git during pushing changes to git remote repository.