Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nomiclabs/hardhat-waffle

NomicFoundation203.3kMIT2.0.6TypeScript support: included

Hardhat plugin to test smart contracts with Waffle

ethereum, smart-contracts, hardhat, hardhat-plugin, ethers.js

readme

npm hardhat

hardhat-waffle

Hardhat plugin for integration with Waffle.

What

You can use this plugin to build smart contract tests using Waffle in Hardhat, taking advantage of both.

This plugin adds a Hardhat-ready version of Waffle to the Hardhat Runtime Environment, and automatically initializes the Waffle Chai matchers.

Installation

npm install --save-dev @nomiclabs/hardhat-waffle 'ethereum-waffle@^3.0.0' @nomiclabs/hardhat-ethers 'ethers@^5.0.0' @types/sinon-chai@^3.2.3

And add the following statement to your hardhat.config.js:

require("@nomiclabs/hardhat-waffle");

Or, if you are using TypeScript, add this to your hardhat.config.ts:

import "@nomiclabs/hardhat-waffle";

Tasks

This plugin creates no additional tasks.

Environment extensions

This plugin adds a waffle object to the Hardhat Runtime Environment. This object has all the Waffle functionality, already adapted to work with Hardhat.

The waffle object has these properties:

  • provider
  • deployContract
  • solidity
  • link
  • deployMockContract
  • createFixtureLoader
  • loadFixture

This plugin depends on @nomiclabs/hardhat-ethers, so it also injects an ethers object into the HRE, which is documented here.

Usage

Once installed, you can build your tests almost like in Waffle.

Instead of importing things from ethereum-waffle, you access them from the waffle property of the Hardhat Runtime Environment.

For example, instead of doing

const { deployContract } = require("ethereum-waffle");

you should do

const { waffle } = require("hardhat");
const { deployContract } = waffle;

Also, you don't need to call chai.use in order to use Waffle's Chai matchers.

Note that by default, Hardhat saves its compilation output into artifacts/ instead of build/. You can either use that directory in your tests, or customize your Hardhat config.

changelog

@nomiclabs/hardhat-waffle

2.0.6

Patch Changes

  • 7926cc9: Support Waffle ^4.0.8

2.0.5

Patch Changes

  • 36441d8: Add hardhat chai matchers incompatibility check
  • c5b5c29: Introduce skipEstimateGas and injectCallHistory fields to hardhat config

2.0.3

Patch Changes

  • bc940060: Improve how errors are created in the hardhat-waffle plugin (#2307)

2.0.2

Patch Changes

  • 8327d8c6: Add support for the hexEqual matcher (#2200)