# ethers-multisend

> A package for crafting multi-send transaction from a Zodiac Avatar, such as a Safe, based on ethers.js

Latest version **3.1.0** (published 2024-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install ethers-multisend
pnpm add ethers-multisend
yarn add ethers-multisend
bun add ethers-multisend
```

## 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 | 3.1.0 |
| Published | 2024-05-31 |
| First published | 2021-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 91 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Jan-Felix Schwarz |
| Maintainers | jfschwarz |

## Links

- npm: https://www.npmjs.com/package/ethers-multisend
- Repository: https://github.com/gnosisguild/ethers-multisend
- Homepage: https://github.com/gnosisguild/ethers-multisend#readme
- Issues: https://github.com/gnosisguild/ethers-multisend/issues
- npm.io page: https://npm.io/package/ethers-multisend

## Dependencies (8)

- [@ethersproject/abi](https://npm.io/package/@ethersproject/abi.md) ^5.0.0
- [@ethersproject/bytes](https://npm.io/package/@ethersproject/bytes.md) ^5.0.0
- [@ethersproject/units](https://npm.io/package/@ethersproject/units.md) ^5.0.0
- [@ethersproject/address](https://npm.io/package/@ethersproject/address.md) ^5.0.0
- [@ethersproject/solidity](https://npm.io/package/@ethersproject/solidity.md) ^5.0.0
- [@ethersproject/bignumber](https://npm.io/package/@ethersproject/bignumber.md) ^5.0.0
- [@ethersproject/contracts](https://npm.io/package/@ethersproject/contracts.md) ^5.5.0
- [@ethersproject/abstract-provider](https://npm.io/package/@ethersproject/abstract-provider.md) ^5.5.1

## Recent versions

- 3.1.0 (latest) — 2024-05-31
- 3.0.0 — 2023-10-06
- 2.4.0 — 2022-11-01
- 2.3.0 — 2022-08-26
- 2.2.0 — 2022-06-30
- 2.1.1 — 2021-12-23
- 2.1.0 — 2021-12-23
- 2.0.1 — 2021-11-16
- 2.0.0 — 2021-11-08
- 1.0.2 — 2021-10-20
- 1.0.1 — 2021-10-20
- 1.0.0 — 2021-10-20

## README

# ethers-multisend

[![Build Status](https://github.com/gnosisguild/ethers-multisend/actions/workflows/ci.yml/badge.svg)](https://github.com/gnosisguild/ethers-multisend/actions/workflows/ci.yml)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/gnosisguild/CODE_OF_CONDUCT)

An npm package for crafting multi-send transaction from a Safe, based on ethers.js v5.

## Features

- Easily encode the most common types of transactions from JSON inputs:
  - ETH & ERC20 token transfers
  - NFT transfers
  - Contract function calls
  - Raw transactions
- Encode a batch of transactions into a single [multi-send call](https://github.com/safe-global/safe-smart-account/blob/main/contracts/libraries/MultiSend.sol).

## What to do with the encoded transaction objects?

The encode functions produce JavaScript objects that can be used to actually execute the described transactions.
There are various ways to do that, using direct calls to your Safe contract, or by relaying it using the infrastructure provided by Safe.
Check out the Safe{Core} SDK to learn more: https://github.com/safe-global/safe-core-sdk

## Installation

This module is distributed via npm. For adding it to your project, run:

```
npm install --save ethers-multisend
```

To install it using yarn, run:

```
yarn add ethers-multisend
```

## API

## encodeSingle

```ts
encodeSingle(transactionInput: TransactionInput): MetaTransaction
```

Encodes a single transaction input and turns into an format that is ready for execution.

## encodeMulti

```ts
encodeMulti(
  metaTransaction: MetaTransaction[],
  multiSendContractAddress?: string
): MetaTransaction
```

Batches a set of meta transactions into a single multi-send contract call.

You can optionally provide the `multiSendContractAddress` to use. By default, it will use [MultiSendCallOnly v1.4.1](https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.4.1/multi_send_call_only.json) or [MultiSend v1.4.1](https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.4.1/multi_send.json) if the batch includes any delegate calls.

## decodeSingle

```ts
decodeSingle(
  metaTransaction: MetaTransaction,
  provider: Provider,
  fetchAbi?: (address: string) => Promise<string | undefined>,
  id?: string
): Promise<TransactionInput>
```

Decodes a meta transaction and returns a transaction input object of one of the four supported types.
It needs an ethers provider instance to fetch decimals for ERC20 token transfers, and a function for fetching the ABI for a contract address.

## decodeMulti

```ts
decodeMulti(data: string): MetaTransaction[]
```

Given the data string of a multi-send transaction, returns an array of the included meta transactions.

## createTransaction

```ts
createTransaction(type: TransactionType, id?: string): TransactionInput
```

Creates an empty transaction input of the specified type.

## isValid

```ts
isValid(transactionInput: TransactionInput): boolean
```

Returns whether the provided transaction input can be encoded into a meta transaction without errors and has a valid `to` address.

## Types

The `TransactionInput` type captures the information for any of the four supported transaction types.

```ts
type TransactionInput =
  | CallContractTransactionInput
  | TransferFundsTransactionInput
  | TransferCollectibleTransactionInput
  | RawTransactionInput
```

The library's encoding functions return objects of the `MetaTransaction` type, which is a format with an ABI encoded `data` field so it is ready for execution.

```ts
interface MetaTransaction {
  readonly to: string
  readonly value: string
  readonly data: string
  readonly operation?: OperationType
}
```

Find the full information about all TypeScript types here: [src/types.ts](src/types.ts)

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