Hardhatのセットアップ
プロジェクトのひな形作成
「Hardhatのセットアップ」はCoddyKit上の無料Web3 & DApp Development Fundamentalsレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb3 & DApp Development Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「Hardhatのセットアップ」レッスンは無料ですか?
はい。「Hardhatのセットアップ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web3 & DApp Development Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。
「Hardhatのセットアップ」で何を学びますか?
プロジェクトのひな形作成 ブラウザで直接実行するハンズオンコードでWeb3 & DApp Development Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Web3 & DApp Development Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのWeb3 & DApp Development Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「Hardhatのセットアップ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このWeb3 & DApp Development Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのWeb3 & DApp Development Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Hardhatのセットアップ
- コントラクトのコンパイル
- スクリプトとタスク
- ローカルネットワークとフォーク