github NomicFoundation/hardhat hardhat@2.13.0
Hardhat v2.13.0 — ES Modules and compiling with viaIR

latest releases: hardhat@2.22.12, hardhat@2.22.11, @nomicfoundation/hardhat-verify@2.0.11...
19 months ago

This new version of Hardhat adds two long-awaited features: ES Modules support, and better support for solc’s IR-based compilation pipeline. Besides that, this version includes several other improvements and bug fixes.

Remember to give this repo a star ⭐ if you are enjoying Hardhat!

ES Modules support

Hardhat was designed with CommonJS in mind, but in the last years adoption of ES Modules (ESM) has been growing. This version includes better support for it. You can now write scripts and tests as ESM, but your Hardhat config —and anything imported from it— still needs to use CommonJS.

ES modules let you use import/export and top-level await. This means that instead of writing a script like this:

// script.js
const helpers = require("@nomicfoundation/hardhat-network-helpers");

async function main() {
  const latestBlockNumber = await helpers.time.latestBlock();
  console.log("Latest block:", latestBlockNumber);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

you can now write a less verbose ESM script:

// script.mjs <-- notice the extension
import helpers from "@nomicfoundation/hardhat-network-helpers";

const latestBlockNumber = await helpers.time.latestBlock();
console.log("Latest block:", latestBlockNumber);

Check our guide about Using ES modules with Hardhat to learn more.

Huge thanks to @phated, who started the work on this and helped us along the way.

IR-based compilation pipeline

The solc compiler has a newer, alternative way of generating bytecode through an intermediate representation (IR). Previous versions of Hardhat don’t work well with this compilation mode, especially when the optimizer is fully-enabled.

This release adds better support for the IR compilation pipeline, but you might still get some issues if you use the default settings. We recommend enabling the minimal necessary optimization steps when compiling with IR:

solidity: {
  version: "0.8.18",
  settings: {
    viaIR: true,
    optimizer: {
      enabled: true,
      details: {
        yulDetails: {
          optimizerSteps: "u:",
        },
      },
    },
  },
}

You can learn more about Hardhat and IR here.

Other improvements

In addition to ES Modules and compiling with the IR-based pipeline, this version includes these improvements and bug fixes:

  • Added support for Solidity 0.8.18 (thanks @taxio!)
  • Hardhat's task runner now allows you to override the arguments passed to subtasks (thanks @zemse!)
  • The colors used to show errors and warnings are better and more readable (thanks @frangio!)
  • We now show better error messages when a transaction to a JSON-RPC network reverts (thanks @orenyomtov!)
  • Hardhat is now more tolerant to Node.js versions that are not officially supported (thanks @iamrekas!)
  • The resolveJsonModule compiler option is now enabled by default in the sample tsconfig (thanks @mlshv!)
  • The sample project’s deploy script uses better example values (thanks @mutedSpectre!)
  • Fixed an issue with a warning showing the same solc version multiple times (thanks @shark0der!)
  • Fixed an error that could happen when a download failed

Don't miss a new hardhat release

NewReleases is sending notifications on new releases.