Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@samouraiwallet/electrum-client

Dojo-Open-Source-Project356LGPL-3.01.5.2TypeScript support: included

Electrum protocol client for Node.js

bitcoin, electrum, electrumx

readme

@samouraiwallet/electrum-client

Efficient and no-dependency Electrum Protocol client for Node.js.

This library uses ESModules, Node.js v18 or higher is required.

Based on

Features

  • No dependencies
  • Persistence (ping strategy and reconnection)
  • Batch requests
  • Promise API
  • Fully typed (Typescript)

Protocol spec

Usage

import {ElectrumClient} from "@samouraiwallet/electrum-client";

const run = async () => {
    const tcpClient = await ElectrumClient.createClient({
        port: 60001,
        host: "btc.electroncash.dk",
        protocol: "tcp",
        electrumConfig: { client: "electrum-client-js", version: ["1.2", "1.4"] },
        persistencePolicy: { retryPeriod: 2000 },
    });

    const rawTx = await tcpClient.blockchainTransaction_get('b270b8a113c048ed0024e470e3c7794565c2b3e18c600d20410ec8f454b7d25a');

    return rawTx;
    // result: 02000000016016c6d039cbdeefa655e4b5ac61ec2b5fe16920529f086a2439f59a5994bed6200000006a4730440220421b5daf5f72e514075d256121d6b66e1d9a8993d37ceb0532baca11f6964da502205333d1c4b9be749180bfa8da4da6a07c0e9e2d853c809a75c4b60ef717a628b20121029139c783aa8f31707a67248a6a6b643855e9d1484dbd53cfe7d9e3adf3ce7098ffffffff02c19a01000000000017a9146eda8b447af853746f04b902fea5b2cd959d866d87692c0200000000001976a914443674ce759f8fa2fe83a6608339da782b890c1988ac00000000
}

changelog

Changelog

1.5.2 (2024-09-29)

  • Added {rejectUnauthorized: false} to TLSSocket

1.5.1 (2024-09-29)

  • Fixed socket connecting preemptively

1.5.0 (2024-09-27)

  • Removed unnecessary boilerplate (TlsSocketWrapper)
  • Added static createClient method for more convenience
  • Updated dependencies

  • (DEV) - Updated to Node.js v18

  • (DEV) - Swtiched to PNPM
  • (DEV) - Switched from eslint to biome

1.4.0 (2023-05-24)

  • Updated keepAlive to use interval instead of timeout
  • Fixed setTimeout on TlsSocketWrapper
  • Updated dependencies

1.3.0 (2022-12-08)

  • Updated TLS wrapper
  • Updated dependencies
  • Switched from mocha to vitest

1.2.4 (2022-03-11)

  • Fixed type of protocol version in config

1.2.3 (2022-03-02)

  • Removed faulty parameter from blockchain.headers.subscribe call

1.2.2 (2022-03-02)

  • Fixed ES module definition

1.2.0 (2022-03-01)

  • Complete rewrite to Typescript
  • Added mocha tests
  • Added ESlint
  • Minor changes and fixes