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.
Using the Hardhat Runtime Environment
Section titled “Using the Hardhat Runtime Environment”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: TheHookManagerused by plugins to customize Hardhat’s behavior.interruptions: TheUserInterruptionsManagerused by plugins to safely handle I/O from Hook Handlers.solidity: The Solidity build system.tasks: TheTaskManagerused 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";