0Pricing
Web3 & DApp Development Fundamentals · Lesson

Hardhat Setup

Project scaffolding.

Hardhat Setup is a free Web3 & DApp Development Fundamentals lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web3 & DApp Development Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is Hardhat

Hardhat is a development environment for Ethereum that helps you compile, test, deploy, and debug smart contracts.

  • Written in JavaScript/TypeScript and run with Node.js.
  • Ships with a built-in local Ethereum network.
  • Has a rich plugin ecosystem (ethers, waffle, gas reporter).

It is the most popular alternative to Truffle and Foundry for JS-centric teams.

Prerequisites

Before installing Hardhat you need Node.js (LTS recommended) and a package manager such as npm or yarn.

Check your versions to make sure the toolchain is ready:

node -v npm -v

Hardhat targets Node.js LTS releases, so avoid odd-numbered experimental versions.

node -v
npm -v

Creating a Project Folder

Each Hardhat project lives in its own directory with a local package.json. Start by creating and initializing the folder:

mkdir my-dapp cd my-dapp npm init -y

This package.json will track Hardhat and your other dev dependencies.

mkdir my-dapp
cd my-dapp
npm init -y

Installing Hardhat

Install Hardhat as a dev dependency so it is not bundled into production:

npm install --save-dev hardhat

Installing locally (not globally) pins the exact version per project, which keeps builds reproducible across machines and CI.

npm install --save-dev hardhat

Scaffolding a Project

Run the Hardhat init wizard to scaffold a starter project:

npx hardhat init

You can choose a JavaScript or TypeScript project, or an empty config. The wizard creates sample contracts, tests, and a config file.

npx hardhat init

Project Structure

A typical Hardhat project layout looks like this:

  • contracts/ — your Solidity source files.
  • scripts/ — deployment and automation scripts.
  • test/ — Mocha/Chai test files.
  • hardhat.config.js — central configuration.
  • artifacts/ and cache/ — generated build output.

The Config File

The hardhat.config.js file is the heart of your setup. A minimal config just exports the Solidity version:

require("@nomicfoundation/hardhat-toolbox"); module.exports = { solidity: "0.8.24", };

You will later extend it with networks, plugins, and compiler settings.

require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  solidity: "0.8.24",
};

The Hardhat Toolbox

The Hardhat Toolbox bundles the most common plugins in one package:

  • ethers.js integration.
  • Chai matchers for assertions.
  • Gas reporter and coverage.
  • Etherscan verification.
npm install --save-dev @nomicfoundation/hardhat-toolbox
npm install --save-dev @nomicfoundation/hardhat-toolbox

Running Hardhat Tasks

Hardhat exposes its functionality through tasks. List all available tasks with:

npx hardhat

Common built-in tasks include compile, test, node, and clean. You always run them via npx to use the local install.

npx hardhat

A First Contract

Add a simple contract under contracts/Greeter.sol:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract Greeter { string public greeting = "Hello, Hardhat"; }

The public state variable automatically gets a getter you can call after deployment.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Greeter {
    string public greeting = "Hello, Hardhat";
}

Git and Ignore Rules

Generated folders should not be committed. Create a .gitignore:

node_modules artifacts cache .env

Keeping .env ignored protects secrets like private keys and RPC URLs from leaking into version control.

node_modules
artifacts
cache
.env

Quick Check

Test your understanding of Hardhat project setup.

Recap

You set up a Hardhat project from scratch.

  • Hardhat is a Node.js-based Ethereum dev environment.
  • npx hardhat init scaffolds contracts, scripts, tests, and config.
  • hardhat.config.js defines Solidity version, networks, and plugins.
  • The Toolbox bundles ethers, Chai matchers, gas reporting, and verification.
  • Ignore node_modules, artifacts, cache, and .env in Git.

Frequently asked questions

Is the “Hardhat Setup” lesson free?

Yes — the full text of “Hardhat Setup” is free to read here on the web, and the Web3 & DApp Development Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web3 & DApp Development Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Hardhat Setup”?

Project scaffolding. You practise Web3 & DApp Development Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Web3 & DApp Development Fundamentals?

No prior experience is required. Web3 & DApp Development Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Hardhat Setup” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Web3 & DApp Development Fundamentals lesson?

Yes. Every Web3 & DApp Development Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Hardhat Setup
  2. Compiling Contracts
  3. Scripts and Tasks
  4. Local Network and Forking
← Back to Web3 & DApp Development Fundamentals