0Pricing
Web3 & DApp Development Fundamentals · Lezione

Configurazione di Hardhat

Impalcatura del progetto

Configurazione di Hardhat è una lezione Web3 & DApp Development Fundamentals gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Web3 & DApp Development Fundamentals, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Web3 & DApp Development Fundamentals include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Configurazione di Hardhat» è gratuita?

Sì — il testo completo di «Configurazione di Hardhat» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Web3 & DApp Development Fundamentals, passa a CoddyKit PRO. Il corso Web3 & DApp Development Fundamentals include 4 lezioni in totale.

Cosa imparerò in «Configurazione di Hardhat»?

Impalcatura del progetto Eserciti Web3 & DApp Development Fundamentals con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Web3 & DApp Development Fundamentals?

Non è richiesta alcuna esperienza precedente. Web3 & DApp Development Fundamentals su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.

Quanto tempo richiede la lezione «Configurazione di Hardhat»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Web3 & DApp Development Fundamentals?

Sì. Ogni lezione Web3 & DApp Development Fundamentals include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Configurazione di Hardhat
  2. Compilazione dei contratti
  3. Script e task
  4. Rete locale e fork
← Torna a Web3 & DApp Development Fundamentals