0Pricing
Web3 & DApp Development Fundamentals · Lektion

Hardhat-Einrichtung

Projektgerüst

Hardhat-Einrichtung ist eine kostenlose Web3 & DApp Development Fundamentals-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Web3 & DApp Development Fundamentals-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Web3 & DApp Development Fundamentals-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Hardhat-Einrichtung“ kostenlos?

Ja — der vollständige Text von „Hardhat-Einrichtung“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Web3 & DApp Development Fundamentals-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Web3 & DApp Development Fundamentals-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Hardhat-Einrichtung“?

Projektgerüst Du übst Web3 & DApp Development Fundamentals mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Web3 & DApp Development Fundamentals zu starten?

Keine Vorkenntnisse erforderlich. Web3 & DApp Development Fundamentals auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Hardhat-Einrichtung“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Web3 & DApp Development Fundamentals-Lektion Code schreiben und ausführen?

Ja. Jede Web3 & DApp Development Fundamentals-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Hardhat-Einrichtung
  2. Contracts kompilieren
  3. Skripte und Tasks
  4. Lokales Netzwerk und Forking
← Zurück zu Web3 & DApp Development Fundamentals