Penyiapan Hardhat
Kerangka proyek
Penyiapan Hardhat adalah pelajaran Web3 & DApp Development Fundamentals gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Web3 & DApp Development Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Web3 & DApp Development Fundamentals mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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.
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Penyiapan Hardhat” gratis?
Ya — teks lengkap “Penyiapan Hardhat” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Web3 & DApp Development Fundamentals, upgrade ke CoddyKit PRO. Kursus Web3 & DApp Development Fundamentals mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Penyiapan Hardhat”?
Kerangka proyek Kamu berlatih Web3 & DApp Development Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Web3 & DApp Development Fundamentals?
Tidak diperlukan pengalaman sebelumnya. Web3 & DApp Development Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.
Berapa lama pelajaran “Penyiapan Hardhat” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Web3 & DApp Development Fundamentals ini?
Ya. Setiap pelajaran Web3 & DApp Development Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Penyiapan Hardhat
- Mengompilasi Kontrak
- Skrip dan Tugas
- Jaringan Lokal dan Forking