<
<
<
Hardhat 3 is now production ready. Migrate now
>
>
>

#hardhat-ethers-chai-matchers

This plugin adds Ethereum-specific matchers to the Chai assertion library that integrate with ethers.js, making your smart contract tests easy to write and read.

#Installation

This plugin is part of the Ethers+Mocha Hardhat Toolbox. If you are using that toolbox, there's nothing else you need to do.

To install this plugin, run the following command:

npm install --save-dev @nomicfoundation/hardhat-ethers-chai-matchers

In your hardhat.config.ts file, import the plugin and add it to the plugins array:

import hardhatEthersChaiMatchers from "@nomicfoundation/hardhat-ethers-chai-matchers";

export default {
  plugins: [hardhatEthersChaiMatchers],
};

#Usage

You don't need to do anything else to use this plugin. Whenever you run your tests with Hardhat, it will automatically add the matchers.

Here is an example of using the emit matcher:

import { expect } from "chai";

it("some test", async function () {
  const contract = await ethers.deployContract("SomeContract");

  await expect(contract.someFunction())
    .to.emit(contract, "SomeEvent")
    .withArgs("0x...", 3);
});