# @ethereum-waffle/provider

> A mock provider for your blockchain testing needs.

Latest version **4.0.5** (published 2023-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ethereum-waffle/provider
pnpm add @ethereum-waffle/provider
yarn add @ethereum-waffle/provider
bun add @ethereum-waffle/provider
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.5 |
| Published | 2023-01-26 |
| First published | 2020-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10.0 |
| Dependencies | 4 |
| Unpacked size | 245.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 959 |
| Author | Marek Kirejczyk |
| Maintainers | ethworks |
| Keywords | ethereum, smart-contracts, solidity, testing, javascript, typescript, library |

## Links

- npm: https://www.npmjs.com/package/@ethereum-waffle/provider
- Repository: https://github.com/EthWorks/Waffle
- Issues: https://github.com/EthWorks/Waffle/issues
- npm.io page: https://npm.io/package/@ethereum-waffle/provider

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^4.3.4
- [ganache](https://npm.io/package/ganache.md) 7.4.3
- [@ethereum-waffle/ens](https://npm.io/package/@ethereum-waffle/ens.md) 4.0.3
- [@ganache/ethereum-options](https://npm.io/package/@ganache/ethereum-options.md) 0.1.4

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 4.0.5 (latest) — 2023-01-26
- 4.0.5-dev.238c11c (dev) — 2023-10-12
- 4.0.4 (alpha) — 2022-08-19
- 3.0.0-beta.3 (beta) — 2020-06-12
- 4.0.5-dev.efd5f2a — 2023-10-12
- 4.0.5-dev.0915e72 — 2023-02-15
- 4.0.5-dev.4740ec6 — 2023-02-06
- 4.0.5-dev.a1d89d0 — 2023-01-27
- 4.0.5-dev.f8ca718 — 2023-01-26
- 4.0.5-dev.13d1af0 — 2023-01-26
- 4.0.5-dev.0bc9af4 — 2023-01-26
- 4.0.5-dev.166b72c — 2023-01-26
- 4.0.5-dev.a50814e — 2023-01-24
- 4.0.5-dev.4d27a34 — 2023-01-23
- 4.0.5-dev.e1d3ccd — 2023-01-11
- … 141 more at https://npm.io/package/@ethereum-waffle/provider/versions

## README

![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/provider.svg)](https://www.npmjs.com/package/@ethereum-waffle/provider)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)

# @ethereum-waffle/provider

A mock provider for your blockchain testing needs.

## Installation

In the current version of waffle (v2.x.x) you will install this package as a dependency of the main waffle package - `ethereum-waffle`.

```
yarn add --dev ethereum-waffle
npm install --save-dev ethereum-waffle
```

If you want to use this package directly please install it via:
```
yarn add --dev @ethereum-waffle/provider
npm install --save-dev @ethereum-waffle/provider
```

## Feature overview

**NOTE**: You do not need to use this package directly. You can install it through the main package (`ethereum-waffle`) and use it instead.

### MockProvider

The `MockProvider` class is the main way of interacting with the blockchain in your waffle tests.

It wraps `ganache-core` in an `ethers` provider and extends it with useful functionality.

You can learn more about it [in the documentation](https://ethereum-waffle.readthedocs.io/en/latest/basic-testing.html).

### Usage

Examples of creating `MockProvider` and usage `getWallets` function:
```ts
import {expect} from 'chai';
import {MockProvider} from '@ethereum-waffle/provider';

describe('waffle tests', async () => {
  it('wallets have non-zero balance', async () => {
    const provider = new MockProvider();
    const wallets = provider.getWallets();
    const balance = await wallets[0].getBalance();
    expect(balance.gt(0)).to.equal(true)
  })
})
```

Use `setupENS` function to set up your `ens` and setting ens address to the provider's networks. The function accepts
the `wallet` as an argument, and if you call it without an argument, it will use the last `wallet` from `MockProvider`.

```ts
import {expect} from 'chai';
import {MockProvider} from '@ethereum-waffle/provider';
describe('waffle tests', async () => {
  it('setup ens', async () => {
    const provider = new MockProvider();
    await provider.setupENS();
    expect(provider.network.ensAddress).to.eq(provider.ens.ens.address);
  });
});
```


### Fixtures

Fixtures are an advanced concept that you can use to make your tests run faster. They take advantage of the snapshot mechanism in Ganache.

You can learn more about it [in the documentation](https://ethereum-waffle.readthedocs.io/en/latest/fixtures.html).

### Legacy API

- `createMockProvider` - this was the old way to construct a MockProvider instance
- `getGanacheOptions` - previously it was possible to load the options from the waffle config file
- `getWallets` - this was the old way to get wallets from a provider

---
_Source: https://npm.io/package/@ethereum-waffle/provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
