Konfiguracja Hardhat
Szkielet projektu
Konfiguracja Hardhat to bezpłatna lekcja Web3 & DApp Development Fundamentals na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Web3 & DApp Development Fundamentals, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Web3 & DApp Development Fundamentals zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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 -vHardhat targets Node.js LTS releases, so avoid odd-numbered experimental versions.
node -v
npm -vCreating 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 -yThis package.json will track Hardhat and your other dev dependencies.
mkdir my-dapp
cd my-dapp
npm init -yInstalling Hardhat
Install Hardhat as a dev dependency so it is not bundled into production:
npm install --save-dev hardhatInstalling locally (not globally) pins the exact version per project, which keeps builds reproducible across machines and CI.
npm install --save-dev hardhatScaffolding a Project
Run the Hardhat init wizard to scaffold a starter project:
npx hardhat initYou can choose a JavaScript or TypeScript project, or an empty config. The wizard creates sample contracts, tests, and a config file.
npx hardhat initProject 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/andcache/— 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-toolboxnpm install --save-dev @nomicfoundation/hardhat-toolboxRunning Hardhat Tasks
Hardhat exposes its functionality through tasks. List all available tasks with:
npx hardhatCommon built-in tasks include compile, test, node, and clean. You always run them via npx to use the local install.
npx hardhatA 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
.envKeeping .env ignored protects secrets like private keys and RPC URLs from leaking into version control.
node_modules
artifacts
cache
.envQuick 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 initscaffolds contracts, scripts, tests, and config.hardhat.config.jsdefines Solidity version, networks, and plugins.- The Toolbox bundles ethers, Chai matchers, gas reporting, and verification.
- Ignore
node_modules,artifacts,cache, and.envin Git.
Często zadawane pytania
Czy lekcja „Konfiguracja Hardhat” jest bezpłatna?
Tak — pełny tekst „Konfiguracja Hardhat” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Web3 & DApp Development Fundamentals, przejdź na CoddyKit PRO. Kurs Web3 & DApp Development Fundamentals zawiera 4 lekcji w sumie.
Co nauczysz się w „Konfiguracja Hardhat”?
Szkielet projektu Ćwiczysz Web3 & DApp Development Fundamentals z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Web3 & DApp Development Fundamentals?
Nie wymagamy żadnego doświadczenia. Web3 & DApp Development Fundamentals w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.
Ile czasu zajmuje lekcja „Konfiguracja Hardhat”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Web3 & DApp Development Fundamentals?
Tak. Każda lekcja Web3 & DApp Development Fundamentals zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Konfiguracja Hardhat
- Kompilowanie kontraktów
- Skrypty i zadania
- Sieć lokalna i forking