#Migrating from Waffle
This page explains how to migrate from Waffle to Hardhat Chai Matchers, and the advantages of doing it.
# How to migrate
The @nomicfoundation/hardhat-chai-matchers
plugin is meant to be a drop-in replacement for the @nomiclabs/hardhat-waffle
plugin. To migrate, follow these instructions:
-
Uninstall the
@nomiclabs/hardhat-waffle
andethereum-waffle
packages:npmyarnnpm uninstall @nomiclabs/hardhat-waffle ethereum-waffle
yarn remove @nomiclabs/hardhat-waffle ethereum-waffle
-
Then install the Hardhat Chai Matchers plugin:
npmyarnnpm install @nomicfoundation/hardhat-chai-matchers
yarn add @nomicfoundation/hardhat-chai-matchers
-
In your Hardhat config, import the Hardhat Chai Matchers plugin and remove the
hardhat-waffle
one:TypeScriptJavaScript- import "@nomiclabs/hardhat-waffle"; + import "@nomicfoundation/hardhat-chai-matchers";
- require("@nomiclabs/hardhat-waffle"); + require("@nomicfoundation/hardhat-chai-matchers");
-
If you were not importing the
@nomiclabs/hardhat-ethers
plugin explicitly (because the Hardhat Waffle plugin already imported it), then add it to your config:TypeScriptJavaScriptimport "@nomiclabs/hardhat-ethers";
require("@nomiclabs/hardhat-ethers");
# Why migrate?
The Hardhat Chai Matchers are compatible with Waffle's API and offer several advantages:
- More features: the Hardhat Chai Matchers include new matchers, like
.revertedWithCustomError
and.revertedWithPanic
, which let you perform better assertions of a transaction's revert reason. - Support for native BigInts: Besides numbers and ethers’s BigNumbers, you can also use JavaScript's native BigInts in your assertions, which means being able to do things like
expect(await token.totalSupply()).to.equal(10n**18n)
instead ofexpect(await token.totalSupply()).to.equal(ethers.BigNumber.from("1000000000000000000"))
. - More reliable: Several problems and minor bugs in Waffle's matchers are fixed in the Hardhat Chai Matchers.