# @chainsafe/libp2p-gossipsub

> A typescript implementation of gossipsub

Latest version **14.1.2** (published 2025-09-18) · Apache-2.0 license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 14.1.2 |
| Published | 2025-09-18 |
| First published | 2022-05-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 14 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 166 |
| Author | Cayman Nava |
| Maintainers | wemeetagain |
| Keywords | libp2p, pubsub, gossip |

## Links

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

## Dependencies (14)

- [denque](https://npm.io/package/denque.md) ^2.1.0
- [it-pipe](https://npm.io/package/it-pipe.md) ^3.0.1
- [it-pushable](https://npm.io/package/it-pushable.md) ^3.2.3
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^5.0.1
- [multiformats](https://npm.io/package/multiformats.md) ^13.0.1
- [@libp2p/crypto](https://npm.io/package/@libp2p/crypto.md) ^5.0.0
- [@libp2p/pubsub](https://npm.io/package/@libp2p/pubsub.md) ^10.0.0
- [uint8arraylist](https://npm.io/package/uint8arraylist.md) ^2.4.8
- [@libp2p/peer-id](https://npm.io/package/@libp2p/peer-id.md) ^5.0.0
- [protons-runtime](https://npm.io/package/protons-runtime.md) ^5.5.0
- [@libp2p/interface](https://npm.io/package/@libp2p/interface.md) ^2.0.0
- [it-length-prefixed](https://npm.io/package/it-length-prefixed.md) ^9.0.4
- [@multiformats/multiaddr](https://npm.io/package/@multiformats/multiaddr.md) ^12.1.14
- [@libp2p/interface-internal](https://npm.io/package/@libp2p/interface-internal.md) ^2.0.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 14.1.2 (latest) — 2025-09-18
- 14.1.1 — 2025-03-28
- 14.1.0 — 2024-09-13
- 14.0.0 — 2024-09-11
- 13.2.0 — 2024-08-19
- 13.1.1 — 2024-08-12
- 13.1.0 — 2024-06-25
- 13.0.0 — 2024-02-28
- 12.0.0 — 2024-02-10
- 11.2.1 — 2024-02-06
- 11.2.0 — 2024-01-30
- 11.1.0 — 2024-01-16
- 11.0.1 — 2023-12-06
- 11.0.0 — 2023-12-03
- 10.1.1 — 2023-11-22
- … 38 more at https://npm.io/package/@chainsafe/libp2p-gossipsub/versions

## README

# js-libp2p-gossipsub

[![](https://img.shields.io/badge/made%20by-ChainSafe-blue.svg?style=flat-square)](https://chainsafe.io/)
[![Travis CI](https://flat.badgen.net/travis/ChainSafe/gossipsub-js)](https://travis-ci.com/ChainSafe/gossipsub-js)
![ES Version](https://img.shields.io/badge/ES-2017-yellow)
![Node Version](https://img.shields.io/badge/node-10.x-green)

## Table of Contents

- [js-libp2p-gossipsub](#js-libp2p-gossipsub)
  - [Lead Maintainer](#lead-maintainer)
  - [Table of Contents](#table-of-contents)
  - [Specs](#specs)
  - [Install](#install)
  - [Usage](#usage)
  - [API](#api)
    - [Create a gossipsub implementation](#create-a-gossipsub-implementation)
  - [Contribute](#contribute)
  - [License](#license)

## Specs

Gossipsub is an implementation of pubsub based on meshsub and floodsub. You can read the specification [here](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub).

`libp2p-gossipsub` currently implements the [`v1.1`](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md) of the spec.

## Install

`npm install @chainsafe/libp2p-gossipsub`

## Usage

```javascript
import { gossipsub } from '@chainsafe/libp2p-gossipsub'


const libp2p = await createLibp2p({
  // ...
  services: {
    pubsub: gossipsub(options)
  }
});

libp2p.services.pubsub.addEventListener('message', (message) => {
  console.log(`${message.detail.topic}:`, new TextDecoder().decode(message.detail.data))
})

libp2p.services.pubsub.subscribe('fruit')

libp2p.services.pubsub.publish('fruit', new TextEncoder().encode('banana'))
```

## API

### Create a gossipsub implementation

```js
const options = {…}
const gossipsub = gossipsub(options)(libp2p)
```

Options is an optional object with the following key-value pairs:

- **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).
- **`gossipIncoming`**: boolean identifying if incoming messages on a subscribed topic should be automatically gossiped (defaults to **true**).
- **`fallbackToFloodsub`**: boolean identifying whether the node should fallback to the floodsub protocol, if another connecting peer does not support gossipsub (defaults to **true**).
- **`floodPublish`**: boolean identifying if self-published messages should be sent to all peers, (defaults to **true**).
- **`doPX`**: boolean identifying whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted nodes (defaults to **false**).
- **`msgIdFn`**: a function with signature `(message) => string` defining the message id given a message, used internally to deduplicate gossip (defaults to `(message) => message.from + message.seqno.toString('hex')`)
- **`signMessages`**: boolean identifying if we want to sign outgoing messages or not (default: `true`)
- **`strictSigning`**: boolean identifying if message signing is required for incoming messages or not (default: `true`)
- **`messageCache`**: optional, a customized `MessageCache` instance, see the implementation for the interface.
- **`scoreParams`**: optional, a customized peer score parameters Object.
- **`scoreThresholds`**: optional, a customized peer score thresholds Object.
- **`directPeers`**: optional, an array of `AddrInfo` of peers with which we will maintain direct connections.

For the remaining API, see [@libp2p/interface-pubsub](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-pubsub).

## Contribute

This module is actively under development. Please check out the issues and submit PRs!

## License

MIT © ChainSafe Systems

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