# @morpho-labs/ethers-multicall

> ⚡🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

Latest version **3.0.4** (published 2023-02-21) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @morpho-labs/ethers-multicall
pnpm add @morpho-labs/ethers-multicall
yarn add @morpho-labs/ethers-multicall
bun add @morpho-labs/ethers-multicall
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2023-02-21 |
| First published | 2022-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0 |
| Dependencies | 2 |
| Unpacked size | 51.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Romain |
| Maintainers | merlin-egalite, julien-devatom, mathisgd, rubilmax |
| Keywords | ethers, multicall, rpc, call, evm, smart contract |

## Links

- npm: https://www.npmjs.com/package/@morpho-labs/ethers-multicall
- Repository: https://github.com/morpho-labs/ethers-multicall
- Homepage: https://github.com/morpho-labs/ethers-multicall#readme
- Issues: https://github.com/morpho-labs/ethers-multicall/issues
- npm.io page: https://npm.io/package/@morpho-labs/ethers-multicall

## Dependencies (2)

- [ethers](https://npm.io/package/ethers.md) ^5.0.0
- [dataloader](https://npm.io/package/dataloader.md) ^2.2.2

## Recent versions

- 3.0.4 (latest) — 2023-02-21
- 4.0.0 (next) — 2023-02-22
- 3.0.3 — 2023-01-11
- 3.0.2 — 2023-01-11
- 3.0.1 — 2022-11-14
- 3.0.0 — 2022-10-26
- 2.0.1 — 2022-10-12
- 2.0.0 — 2022-09-27
- 1.3.4 — 2022-09-25
- 1.3.3 — 2022-09-25
- 1.3.2 — 2022-09-25
- 1.3.1 — 2022-09-06
- 1.3.0 — 2022-09-05
- 1.2.0 — 2022-09-05
- 1.1.1 — 2022-09-05
- … 4 more at https://npm.io/package/@morpho-labs/ethers-multicall/versions

## README

# ethers-multicall

[![npm package][npm-img]][npm-url]
[![Build Status][build-img]][build-url]
[![Downloads][downloads-img]][downloads-url]
[![Issues][issues-img]][issues-url]
[![Commitizen Friendly][commitizen-img]][commitizen-url]
[![Semantic Release][semantic-release-img]][semantic-release-url]

> ⚡🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

Querying an RPC endpoint can be very costly (**100+ queries**) when loading data from multiple smart contracts.
With multicall, batch these queries into a single, on-chain query, without additional over-head!

This is the standalone package of the library formerly created & used by [Zapper](https://github.com/Zapper-fi/studio/tree/main/src/multicall).

## Install

```bash
npm install @morpho-labs/ethers-multicall
```

```bash
yarn add @morpho-labs/ethers-multicall
```

## Usage

```typescript
import { ethers } from "ethers";

import { EthersMulticall } from "@morpho-labs/ethers-multicall";

const provider = new ethers.providers.JsonRpcBatchProvider("...");
const multicall = new EthersMulticall(provider);

const uni = multicall.wrap(
  new ethers.Contract("0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", UniswapAbi)
); // make sure to always wrap contracts to benefit from multicalls

Promise.all([uni.name(), uni.symbol(), uni.decimals()]).then(console.log);
```

## Limitations

- When performing calls in parallel, a single incorrect call may revert and make the aggregated call to the Multicall contract revert ; effectively throwing multiple errors in your code. The following example illustrates this limitation:

```typescript
const performCall = async (address: string) => {
  const erc20 = await multicall.wrap(new ethers.Contract(address, ERC20Abi));

  try {
    const symbol = await erc20.symbol();
  } catch {
    return console.error("An error occurred while fetching the symbol of token:", address);
  }
};

Promise.all(
  [
    "0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd", // valid GUSD token address
    "0x0000000000000000000000000000000000000000", // invalid ERC20 token address
  ].map(performCall)
);

// prints 2 errors:
// An error occurred while fetching the symbol of token: 0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd
// An error occurred while fetching the symbol of token: 0x0000000000000000000000000000000000000000
```

[build-img]: https://github.com/morpho-labs/ethers-multicall/actions/workflows/release.yml/badge.svg
[build-url]: https://github.com/morpho-labs/ethers-multicall/actions/workflows/release.yml
[downloads-img]: https://img.shields.io/npm/dt/@morpho-labs/ethers-multicall
[downloads-url]: https://www.npmtrends.com/@morpho-labs/ethers-multicall
[npm-img]: https://img.shields.io/npm/v/@morpho-labs/ethers-multicall
[npm-url]: https://www.npmjs.com/package/@morpho-labs/ethers-multicall
[issues-img]: https://img.shields.io/github/issues/morpho-labs/ethers-multicall
[issues-url]: https://github.com/morpho-labs/ethers-multicall/issues
[codecov-img]: https://codecov.io/gh/morpho-labs/ethers-multicall/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/morpho-labs/ethers-multicall
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-url]: https://github.com/semantic-release/semantic-release
[commitizen-img]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
[commitizen-url]: http://commitizen.github.io/cz-cli/

---
_Source: https://npm.io/package/@morpho-labs/ethers-multicall · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
