Registry / blockchain / ws-electrumx-client

ws-electrumx-client

JSON →
library1.0.5jsnpmunverified

Lightweight ElectrumX WebSocket client for Bitcoin and Liquid blockchain interactions. Current stable version 1.0.5, released with TypeScript type definitions. Provides a simple batch request API for sending Electrum JSON-RPC commands over WebSocket connections. Differentiates from alternatives like electrum-client by focusing exclusively on WebSocket transport and providing a minimal, promise-based interface with automatic batch request handling. Suitable for Node.js (>=10) and modern browsers with WebSocket support.

npm install ws-electrumx-client
INSTALL
IMPORT
SIG · WS-ELECTRUMX-CLIEN
W
ws-electrumx-client
blockchainjavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ElectrumWS
import { ElectrumWS } from 'ws-electrumx-client'
const ElectrumWS = require('ws-electrumx-client')
The package is ESM-only; CommonJS require will not work. Always use named import.
ElectrumWS
const { ElectrumWS } = require('ws-electrumx-client')
const ElectrumWS = require('ws-electrumx-client').default
If using CommonJS via dynamic import, destructure the named export. There is no default export.
ElectrumWSConstructorOptions
import type { ElectrumWSConstructorOptions } from 'ws-electrumx-client'
import { ElectrumWSConstructorOptions } from 'ws-electrumx-client'
Options interface is exported as a type; use type-only import to avoid runtime inclusion.

Creates an ElectrumWS client connected to a Liquid testnet WebSocket endpoint and sends a batch request with two methods.

import { ElectrumWS } from 'ws-electrumx-client'; const electrum = new ElectrumWS('wss://blockstream.info/liquidtestnet/electrum-websocket/api'); async function main() { const responses = await electrum.batchRequest( { method: 'blockchain.estimatefee', params: [1] }, { method: 'blockchain.block.header', params: [1] } ); console.log(responses); } main().catch(console.error);
Debug
Known issues
gotchaWebSocket connection may not be immediately open after constructor; use 'onOpen' or 'ready' callback if needed.
fix
Use the client.on('open', callback) or wait for the first batch request to trigger automatic connection.
affects: >=1.0.0
gotchaBatch requests are executed as a single WebSocket message; order of responses corresponds to request order, but individual errors may not propagate correctly if one request fails.
fix
Wrap batchRequest in try/catch and check each response for error field.
affects: >=1.0.0
breakingVersion 1.0.0 dropped support for earlier internal API; clients must migrate from custom RPC methods to batchRequest.
fix
Use batchRequest with method/params objects instead of calling individual RPC methods.
affects: <1.0.0
Errors
Common errors & fixes
Error: Can't resolve 'ws'
Missing 'ws' dependency in browser environment where WebSocket is built-in.
fix
Use a bundler alias to substitute 'ws' with the browser's native WebSocket, or avoid importing 'ws' by ensuring the package is used in a browser context where WebSocket is global.
TypeError: ElectrumWS is not a constructor
Using default import instead of named import.
fix
Change to: import { ElectrumWS } from 'ws-electrumx-client'
Error: Cannot find module 'ws-electrumx-client'
Package not installed or used in a CommonJS environment without proper transpilation.
fix
Install with npm install ws-electrumx-client, or use dynamic import() in CommonJS code.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
wsoptionalWebSocket client for Node.js environments
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
ws-electrumx-client — npm install ws-electrumx-client · libregistry