This page explains how to migrate from Waffle to Hardhat Chai Matchers, and the advantages of doing it.
@nomicfoundation/hardhat-chai-matchers plugin is meant to be a drop-in replacement for the
@nomiclabs/hardhat-waffle plugin. To migrate, follow these instructions:
npm uninstall @nomiclabs/hardhat-waffle ethereum-waffle
yarn remove @nomiclabs/hardhat-waffle ethereum-waffle
Then install the Hardhat Chai Matchers plugin:npmyarn
npm install @nomicfoundation/hardhat-chai-matchers
yarn add @nomicfoundation/hardhat-chai-matchers
In your Hardhat config, import the Hardhat Chai Matchers plugin and remove the
- import "@nomiclabs/hardhat-waffle"; + import "@nomicfoundation/hardhat-chai-matchers";
- require("@nomiclabs/hardhat-waffle"); + require("@nomicfoundation/hardhat-chai-matchers");
If you were not importing the
The Hardhat Chai Matchers are compatible with Waffle's API and offer several advantages:
- More features: the Hardhat Chai Matchers include new matchers, like
.revertedWithPanic, which let you perform better assertions of a transaction's revert reason.
expect(await token.totalSupply()).to.equal(10n**18n)instead of
- More reliable: Several problems and minor bugs in Waffle's matchers are fixed in the Hardhat Chai Matchers.