# @rainbow-me/swaps

> ![Rainbow Swaps Image](../.github/hero.png)

Latest version **0.41.0** (published 2026-02-10) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @rainbow-me/swaps
pnpm add @rainbow-me/swaps
yarn add @rainbow-me/swaps
bun add @rainbow-me/swaps
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.41.0 |
| Published | 2026-02-10 |
| First published | 2022-03-14 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 14 |
| Unpacked size | 841.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bruno Barbieri |
| Maintainers | jinchung, danielsinclair, cbaroni |

## Links

- npm: https://www.npmjs.com/package/@rainbow-me/swaps
- npm.io page: https://npm.io/package/@rainbow-me/swaps

## Dependencies (14)

- [ox](https://npm.io/package/ox.md) 0.9.14
- [@ethereumjs/util](https://npm.io/package/@ethereumjs/util.md) 9.0.0
- [@ethersproject/abi](https://npm.io/package/@ethersproject/abi.md) 5.7.0
- [@ethersproject/bytes](https://npm.io/package/@ethersproject/bytes.md) 5.7.0
- [@ethersproject/wallet](https://npm.io/package/@ethersproject/wallet.md) 5.7.0
- [@ethersproject/strings](https://npm.io/package/@ethersproject/strings.md) 5.7.0
- [@metamask/eth-sig-util](https://npm.io/package/@metamask/eth-sig-util.md) 7.0.0
- [@ethersproject/solidity](https://npm.io/package/@ethersproject/solidity.md) 5.7.0
- [@ethersproject/bignumber](https://npm.io/package/@ethersproject/bignumber.md) 5.7.0
- [@ethersproject/contracts](https://npm.io/package/@ethersproject/contracts.md) 5.7.0
- [@ethersproject/keccak256](https://npm.io/package/@ethersproject/keccak256.md) 5.7.0
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) 5.7.0
- [@ethersproject/transactions](https://npm.io/package/@ethersproject/transactions.md) 5.7.0
- [@ethersproject/abstract-signer](https://npm.io/package/@ethersproject/abstract-signer.md) 5.7.0

## Recent versions

- 0.41.0 (latest) — 2026-02-10
- 0.42.0-beta.2 (beta) — 2026-02-11
- 0.42.0-beta.1 — 2026-02-11
- 0.40.0-beta.3 — 2026-01-23
- 0.40.0 — 2025-12-11
- 0.40.0-beta.2 — 2025-12-04
- 0.40.0-beta.1 — 2025-11-12
- 0.39.0 — 2025-10-29
- 0.38.0 — 2025-10-27
- 0.37.0-beta.2 — 2025-10-15
- 0.37.0-beta.1 — 2025-10-15
- 0.36.0 — 2025-04-02
- 0.35.0 — 2025-03-20
- 0.34.0 — 2025-03-20
- 0.33.0 — 2025-03-20
- … 54 more at https://npm.io/package/@rainbow-me/swaps/versions

## README

![Rainbow Swaps Image](../.github/hero.png)

# Rainbow Swaps SDK

[![npm version](https://img.shields.io/npm/v/@rainbow-me/swaps.svg)](https://www.npmjs.com/package/@rainbow-me/swaps)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Swap aggregator SDK used in Rainbow Wallet.

## Installation

```bash
yarn add @rainbow-me/swaps
```

```bash
npm install @rainbow-me/swaps
```

```bash
pnpm add @rainbow-me/swaps
```

## Usage

### Get a quote for a pair

```typescript
import { getQuote } from '@rainbow-me/swaps';

const quote = await getQuote({
  source,             // optional, "1inch" or "0x"
  chainId,            // numeric chain id
  fromAddress,        // address of the wallet to execute the swap from
  destReceiver,       // optional, address to receive the output tokens
  sellTokenAddress,   // address of the input token
  buyTokenAddress,    // address of the output token
  sellAmount,         // amount of the input token (required if not passing buyAmount)
  buyAmount,          // amount of the output token (required if not passing sellAmount)
  slippage,           // max slippage percentage allowed
});
```

### Estimate gas for the swap

```typescript
import { getQuoteExecutionDetails } from '@rainbow-me/swaps';

const { params, method, methodArgs } = getQuoteExecutionDetails(
  quote,                     // quote returned from getQuote
  { from: quote.from },      // transaction options
  provider                   // ethers provider
);

const estimatedGas = await method(methodArgs);
```

### Execute swap for a given quote

```typescript
import { fillQuote } from '@rainbow-me/swaps';

const hash = await fillQuote(
  quote,                // quote returned from getQuote
  transactionOptions,   // gasLimit, maxFeePerGas, maxPriorityFeePerGas, nonce, value, from
  permit,               // true if you want to use the permit
  chainId               // numeric chain id
);
```

### Prepare fill quote transaction

```typescript
import { prepareFillQuote } from '@rainbow-me/swaps';

const transaction = await prepareFillQuote(
  quote,                // quote returned from getQuote
  transactionOptions,   // gasLimit, maxFeePerGas, maxPriorityFeePerGas, nonce, value, from
  wallet,               // ethers signer
  permit,               // true if you want to use the permit
  chainId               // numeric chain id
);

// Returns a populated transaction object that can be sent later
const hash = await wallet.sendTransaction(transaction);
```

## Features

- Token to ETH swaps
- Token to Token swaps
- ETH to Token swaps
- Use of permit when supported (to avoid an extra approval)
- Supported chains: Mainnet, Optimism, Arbitrum, Polygon, Base, and more

## Development

```bash
nvm use
```

```bash
yarn install
```

```bash
yarn build
```

```bash
yarn test
```

```bash
yarn lint
```

## License

Licensed under the [GPL-3.0 License](../../LICENSE).

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