# @chainsafe/libp2p-yamux

> Yamux stream multiplexer for libp2p

Latest version **8.0.1** (published 2025-10-15) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install @chainsafe/libp2p-yamux
pnpm add @chainsafe/libp2p-yamux
yarn add @chainsafe/libp2p-yamux
bun add @chainsafe/libp2p-yamux
```

## Health

**Score 65/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 8.0.1 |
| Published | 2025-10-15 |
| First published | 2022-09-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 382.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 19 |
| Maintainers | wemeetagain |
| Keywords | IPFS, libp2p, multiplexer, muxer, stream |

## Links

- npm: https://www.npmjs.com/package/@chainsafe/libp2p-yamux
- Repository: https://github.com/ChainSafe/js-libp2p-yamux
- Homepage: https://github.com/ChainSafe/js-libp2p-yamux#readme
- Issues: https://github.com/ChainSafe/js-libp2p-yamux/issues
- npm.io page: https://npm.io/package/@chainsafe/libp2p-yamux

## Dependencies (4)

- [race-signal](https://npm.io/package/race-signal.md) ^2.0.0
- [@libp2p/utils](https://npm.io/package/@libp2p/utils.md) ^7.0.0
- [uint8arraylist](https://npm.io/package/uint8arraylist.md) ^2.4.8
- [@libp2p/interface](https://npm.io/package/@libp2p/interface.md) ^3.0.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 8.0.1 (latest) — 2025-10-15
- 7.0.2-rc.0 (rc) — 2024-10-10
- 8.0.0 — 2025-09-25
- 7.0.4 — 2025-06-25
- 7.0.3 — 2025-06-25
- 7.0.2 — 2025-06-18
- 7.0.1 — 2024-09-25
- 7.0.0 — 2024-09-11
- 6.0.2 — 2024-02-08
- 6.0.1 — 2023-11-30
- 6.0.0 — 2023-11-29
- 5.0.4 — 2023-11-29
- 5.0.3 — 2023-11-14
- 5.0.2 — 2023-11-12
- 5.0.1 — 2023-11-12
- … 19 more at https://npm.io/package/@chainsafe/libp2p-yamux/versions

## README

# @chainsafe/libp2p-yamux

[![codecov](https://img.shields.io/codecov/c/github/ChainSafe/js-libp2p-yamux.svg?style=flat-square)](https://codecov.io/gh/ChainSafe/js-libp2p-yamux)
[![CI](https://img.shields.io/github/actions/workflow/status/ChainSafe/js-libp2p-yamux/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ChainSafe/js-libp2p-yamux/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Yamux stream multiplexer for libp2p

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

This module is a JavaScript implementation of [Yamux from Hashicorp](https://github.com/hashicorp/yamux/blob/master/spec.md) designed to be used with [js-libp2p](https://github.com/libp2p/js-libp2p).

## Example - Configure libp2p with Yamux

```typescript
import { createLibp2p } from 'libp2p'
import { yamux } from '@chainsafe/libp2p-yamux'

const node = await createLibp2p({
  // ... other options
  streamMuxers: [
    yamux()
  ]
})
```

## Example - Using the low-level API

```js
import { yamux } from '@chainsafe/libp2p-yamux'
import { pipe } from 'it-pipe'
import { duplexPair } from 'it-pair/duplex'
import all from 'it-all'

// Connect two yamux muxers to demo basic stream multiplexing functionality

const clientMuxer = yamux({
  client: true,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

const serverMuxer = yamux({
  client: false,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

// `p` is our "connections", what we use to connect the two sides
// In a real application, a connection is usually to a remote computer
const p = duplexPair()

// connect the muxers together
pipe(p[0], clientMuxer, p[0])
pipe(p[1], serverMuxer, p[1])

// now either side can open streams
const stream0 = clientMuxer.newStream()
const stream1 = serverMuxer.newStream()

// Send some data to the other side
const encoder = new TextEncoder()
const data = [encoder.encode('hello'), encoder.encode('world')]
pipe(data, stream0)

// Receive data back
const result = await pipe(stream0, all)

// close a stream
stream1.close()

// close the muxer
clientMuxer.close()
```

# Install

```console
$ npm i @chainsafe/libp2p-yamux
```

## Browser `<script>` tag

Loading this module through a script tag will make its exports available as `ChainsafeLibp2pYamux` in the global namespace.

```html
<script src="https://unpkg.com/@chainsafe/libp2p-yamux/dist/index.min.js"></script>
```

# API Docs

- <https://ChainSafe.github.io/js-libp2p-yamux>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/ChainSafe/js-libp2p-yamux/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/ChainSafe/js-libp2p-yamux/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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