Skip to content

The Hardhat Runtime Environment

The Hardhat Runtime Environment, or HRE for short, is an object containing all the functionality that Hardhat exposes when running a task, test, script, or executing a plugin. You can think of the HRE as being Hardhat itself.

The HRE centralizes coordination across all Hardhat components. This architecture allows plugins to inject functionality that becomes available everywhere the HRE is accessible.

You can use the HRE when you:

  • Run a Hardhat Task: it’s received as a parameter

  • Run a TypeScript test: import it with

    import hre from "hardhat";
  • Run a script: import it with

    import hre from "hardhat";
  • Manually construct it using the functions exported in "hardhat/hre"

The Hardhat Runtime Environment’s functionality

Section titled “The Hardhat Runtime Environment’s functionality”

The Hardhat Runtime Environment has the following properties:

  • config: The resolved config that Hardhat uses.
  • userConfig: The config as provided by the user.
  • artifacts: An object that lets you read the compilation artifacts of your project.
  • network: An object used to connect to live networks and create blockchain simulations.
  • globalOptions: The Global Options of the HRE.
  • hooks: The HookManager used by plugins to customize Hardhat’s behavior.
  • interruptions: The UserInterruptionsManager used by plugins to safely handle I/O from Hook Handlers.
  • solidity: The Solidity build system.
  • tasks: The TaskManager used to run Hardhat Tasks.
  • versions: An object with the version of Hardhat and its key dependencies.

You can also import each of them as named imports, like this:

import {
config,
userConfig,
artifacts,
network,
globalOptions,
hooks,
interruptions,
solidity,
tasks,
versions,
} from "hardhat";