hardhat
Develop, test, and deploy smart contracts
TLDR
List available subcommands (or create a new project if no configuration exists)
Compile the current project and build all artifacts
Run a user-defined script after compiling the project
Run Mocha tests
Run all given test files
Start a local Ethereum JSON-RPC node for development
Start a local Ethereum JSON-RPC node with a specific hostname and port
Clean the cache and all artifacts
SYNOPSIS
npx hardhat [command] [args] [options]
yarn hardhat [command] [args] [options]
The `npx` or `yarn` prefix is crucial as Hardhat is a Node.js package, not a system-level executable.
PARAMETERS
compile
Compiles all Solidity contracts found in the project.
test
Executes all tests written for the smart contracts, typically using JavaScript/TypeScript.
run <script-path>
Runs a specified JavaScript or TypeScript script within the Hardhat environment, useful for deployment or custom tasks.
node
Starts a local Hardhat Network instance, an in-memory Ethereum network ideal for fast development and testing.
clean
Deletes the cache and artifacts directories to ensure a clean build.
help [command]
Displays comprehensive help information for Hardhat itself or a specific command/task.
--network <name>
Specifies the Ethereum network to connect to (e.g., `localhost`, `sepolia`, `mainnet`), as defined in the Hardhat configuration.
--config <path>
Provides an explicit path to the Hardhat configuration file (`hardhat.config.js` or `hardhat.config.ts`).
DESCRIPTION
Hardhat is not a standard, native Linux command. Instead, it is a popular, open-source development environment designed for compiling, deploying, testing, and debugging decentralized applications (dApps) and smart contracts on the Ethereum blockchain. It's primarily a JavaScript/TypeScript project, typically installed via `npm` or `yarn`, and executed using `npx hardhat` or `yarn hardhat` within a project directory. Hardhat provides a robust local Ethereum network (Hardhat Network) for rapid development, a flexible plugin system for extending functionality, and seamless integration with JavaScript and TypeScript testing frameworks. It simplifies the entire smart contract development lifecycle, from writing Solidity code to deploying on mainnet.
CAVEATS
Hardhat is not a native Linux command-line utility. It relies on Node.js and a package manager (`npm` or `yarn`) being installed on the system. Its primary application is in blockchain development for Ethereum and EVM-compatible networks, and it's not part of the standard Linux toolset. Commands are almost always prefixed with `npx` or `yarn` to execute the locally installed Hardhat CLI.
INSTALLATION
Hardhat is typically installed locally within a project using npm: `npm install --save-dev hardhat`. A new project can be initialized by navigating into an empty directory and running `npx hardhat` to set up basic project files. Global installation (`npm install -g hardhat`) is also possible but less common for project-specific development.
CONFIGURATION
Every Hardhat project includes a `hardhat.config.js` (or `.ts`) file. This central configuration file defines networks, Solidity compiler versions, paths to contracts and tests, and enables various plugins. It's essential for tailoring Hardhat's behavior to specific project requirements.
HISTORY
Hardhat was developed by Nomic Labs and officially launched in 2020. It rapidly gained prominence in the Ethereum development community as a modern, robust, and developer-centric alternative to existing tools. Its key innovations, such as the built-in Hardhat Network with console.log functionality for smart contracts and an extensible plugin architecture, significantly improved the development experience for Solidity smart contracts and dApps.