0Pricing
Web3 & DApp Development Fundamentals · Lección

Configuración de Hardhat

Estructura inicial del proyecto

Configuración de Hardhat es una lección gratuita de Web3 & DApp Development Fundamentals en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Web3 & DApp Development Fundamentals, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Web3 & DApp Development Fundamentals incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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.

Preguntas frecuentes

¿La lección «Configuración de Hardhat» es gratis?

Sí — el texto completo de «Configuración de Hardhat» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Web3 & DApp Development Fundamentals, actualiza a CoddyKit PRO. El curso de Web3 & DApp Development Fundamentals incluye 4 lecciones en total.

¿Qué aprenderé en «Configuración de Hardhat»?

Estructura inicial del proyecto Practicas Web3 & DApp Development Fundamentals con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Web3 & DApp Development Fundamentals?

No se requiere experiencia previa. Web3 & DApp Development Fundamentals en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.

¿Cuánto tiempo toma la lección «Configuración de Hardhat»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Web3 & DApp Development Fundamentals?

Sí. Cada lección de Web3 & DApp Development Fundamentals incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Configuración de Hardhat
  2. Compilación de contratos
  3. Scripts y tareas
  4. Red local y forking
← Volver a Web3 & DApp Development Fundamentals