0Pricing
Web3 & DApp Development Fundamentals · Aula

Configuração do Hardhat

Estrutura inicial do projeto

Configuração do Hardhat é uma aula grátis de Web3 & DApp Development Fundamentals no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Web3 & DApp Development Fundamentals, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Web3 & DApp Development Fundamentals inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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.

Perguntas Frequentes

A aula “Configuração do Hardhat” é grátis?

Sim — o texto completo de “Configuração do Hardhat” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Web3 & DApp Development Fundamentals, atualize para CoddyKit PRO. O curso de Web3 & DApp Development Fundamentals inclui 4 aulas no total.

O que vou aprender em “Configuração do Hardhat”?

Estrutura inicial do projeto Você pratica Web3 & DApp Development Fundamentals com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Web3 & DApp Development Fundamentals?

Nenhuma experiência prévia é necessária. Web3 & DApp Development Fundamentals no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Configuração do Hardhat”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Web3 & DApp Development Fundamentals?

Sim. Cada aula de Web3 & DApp Development Fundamentals inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Configuração do Hardhat
  2. Compilação de contratos
  3. Scripts e tarefas
  4. Rede local e forking
← Voltar para Web3 & DApp Development Fundamentals