# @electrum-cash/network

> @electrum-cash/network is a lightweight JavaScript library that lets you connect with one or more Electrum servers.

Latest version **4.3.0** (published 2026-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @electrum-cash/network
pnpm add @electrum-cash/network
yarn add @electrum-cash/network
bun add @electrum-cash/network
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2026-09-16 |
| First published | 2023-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 7 |
| Unpacked size | 103.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Silverblood |
| Maintainers | monsterbitar |
| Keywords | electrum, bitcoin, bitcoin cash |

## Links

- npm: https://www.npmjs.com/package/@electrum-cash/network
- Repository: https://gitlab.com/electrum-cash/network
- Homepage: https://gitlab.com/electrum-cash/network#readme
- Issues: https://gitlab.com/electrum-cash/network/issues
- npm.io page: https://npm.io/package/@electrum-cash/network

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) ^4.3.2
- [async-mutex](https://npm.io/package/async-mutex.md) ^0.5.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.1
- [lossless-json](https://npm.io/package/lossless-json.md) ^4.0.1
- [@electrum-cash/socket](https://npm.io/package/@electrum-cash/socket.md) ^4.0.1
- [@electrum-cash/debug-logs](https://npm.io/package/@electrum-cash/debug-logs.md) ^1.0.0
- [@electrum-cash/web-socket](https://npm.io/package/@electrum-cash/web-socket.md) ^4.0.2

## Recent versions

- 4.3.0 (latest) — 2026-09-16
- 4.3.0-development.16529028959 (development) — 2026-09-16
- 4.2.2 — 2026-02-01
- 4.2.2-development.12944155577 — 2026-02-01
- 4.2.1-development.12824632410 — 2026-01-22
- 4.2.1 — 2026-01-14
- 4.2.1-development.12715316329 — 2026-01-14
- 4.2.0 — 2026-01-14
- 4.2.0-development.12712509126 — 2026-01-14
- 4.1.4-development.12712433163 — 2026-01-14
- 4.1.4-development.12704171077 — 2026-01-13
- 4.1.4-development.12703457447 — 2026-01-13
- 4.1.4-development.11641455551 — 2025-10-08
- 4.1.4 — 2025-09-20
- 4.1.4-development.11427964670 — 2025-09-20
- … 60 more at https://npm.io/package/@electrum-cash/network/versions

## README

# Introduction

@electrum-cash/network is a lightweight `JavaScript` library that lets you connect `Electrum` servers.

It offers encrypted connections by default,
performs the expected protocol version negotiation and
automatically keeps your connection alive until your close it.

## Installation

Install the library with NPM:

```bash
# npm install @electrum-cash/network
```

## Usage

### Importing the library

To use the library, import the `ElectrumClient` into your project:

```js
// Load the electrum library.
import { ElectrumClient } from '@electrum-cash/network';
```

### Connecting to a server

Initialize and connect the client with your **application identifier** and **protocol version**, as well as a **hostname** to connect to.

*(For more control over how the connection is managed, see [ElectrumNetworkOptions](interfaces/ElectrumNetworkOptions.html))*

```js
// Initialize an electrum client.
const electrumClient = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash');

// Wait for the client to connect.
await electrumClient.connect();
```

Alternatively, you can provide a pre-configured `ElectrumSocket` instead of the hostname:

```js
// Set up your own socket, somehow.
const electrumSocket = new MyElectrumSocketClass();

// Initialize the electrum client.
const electrumClient = new ElectrumClient('Electrum client example', '1.4.1', electrumSocket);

// Wait for the client to connect.
await electrumClient.connect();
```

### Request information

Once your `ElectrumClient` is connected and ready, you can call methods:

*For a list of methods you can use, refer to the [Electrum Cash documentation](https://bitcoincash.network/electrum/).*

```js
// Declare an example transaction ID.
const transactionID = '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251';

// Request the full transaction hex for the transaction ID.
const transactionHex = await electrumClient.request('blockchain.transaction.get', transactionID);

// Print out the transaction hex.
console.log(transactionHex);
```

### Subscribe to notifications.

Once your `ElectrumClient` is connected and ready, you can set up subscriptions to get notifications on events:

*For a list of methods you can subscribe to, refer to the [Electrum Cash documentation](https://bitcoincash.network/electrum/).*

```js
// Set up a callback function to handle new blocks.
const handleNotifications = function(data)
{
	if(data.method === 'blockchain.headers.subscribe')
	{
		// Print out the block information.
		// {
		// 	jsonrpc: '2.0',
		// 	method: 'blockchain.headers.subscribe',
		// 	params:
		// 	[
		// 		{
		// 		height: 797111,
		// 		hex: '002001202a6b1367f68201ad957e95bec9bda3f132ca2fcb75c0c000000000000000000074befba60bd8615d87ddb636aa99bc032cec8db3adb0d915d45391bc811c1e9ceacf89647a60051819a79559'
		// 		}
		// 	]
		// }
		console.log(data);
	}
}

// Listen for notifications.
electrumClient.on('notification', handleNotifications);

// Set up a subscription for new block headers.
await electrumClient.subscribe('blockchain.headers.subscribe');
```

### Shutting down

When you're done and don't want to be connected anymore you can disconnect the server:

```js
// Close the connection.
await electrumClient.disconnect();
```

## Documentation

For a complete list of methods and parameters, read the [API documentation](https://electrum-cash.gitlab.io/network/).

## Support and communication

If you need help with how to use the library or just want to talk about electrum-cash, you can find us on [Telegram](https://t.me/electrumcash) and [Discord](https://discord.gg/ZjXQzew).

## Notes

The keep-alive functionality of this library only works when the protocol version is 1.2 or higher.

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