Registry / blockchain / bitsharesjs-ws

bitsharesjs-ws

JSON →
library6.0.2jsnpmunverified

Pure JavaScript BitShares blockchain websocket interface for node.js and browsers (v6.0.2). Allows connection to public or local BitShares API nodes for blockchain data access. Releases follow semver with active development on GitHub. Key differentiator: provides high-level API for Database and History methods with automatic connection management and subscription support. Requires Node >= 16.13.

npm install bitsharesjs-ws
INSTALL
IMPORT
SIG · BITSHARESJS-WS
B
bitsharesjs-ws
blockchainjavascriptv6.0.2
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.

Apis
import { Apis } from 'bitsharesjs-ws'
const Apis = require('bitsharesjs-ws').Apis
Named export, not default. Works with both ESM and CJS. In CJS, 'const { Apis } = require('bitsharesjs-ws')' is correct.
default
import bitshares_ws from 'bitsharesjs-ws'
import { default as bitshares_ws } from 'bitsharesjs-ws'
Default export is available only in ESM context. Not recommended; prefer named exports.
Login
import { Login } from 'bitsharesjs-ws'
const Login = require('bitsharesjs-ws').Login
Login is a named export for API connection with credentials. Also available as instance method via Apis.instance().

Shows how to connect to a public BitShares node, fetch blockchain objects, and subscribe to real-time updates.

import { Apis } from 'bitsharesjs-ws'; // Connect to a public BitShares node Apis.instance('wss://bitshares.openledger.info/ws', true) .init_promise .then(res => { console.log('Connected to network:', res[0].network); // Call Database API return Apis.db.get_objects(['1.3.0', '2.0.0']); }) .then(objects => { console.log('Objects:', objects); // Subscribe to all object updates Apis.db.set_subscribe_callback(updateCallback, true); }) .catch(err => console.error('Connection error:', err)); function updateCallback(object) { console.log('Update:', object); }
Debug
Known issues
breakingSince v5.0.0, the library requires Node.js >= 16.13.0 and npm >= 8.2.0. Older Node versions will fail to install or run.
fix
Upgrade Node to 16.13+ or use an older version of the library (e.g., 4.x).
affects: >=5.0.0
breakingSince v4.0.0, the library is ESM-first. CommonJS require() still works with named exports, but default import via require() is not available.
fix
Use named imports: const { Apis } = require('bitsharesjs-ws').
affects: >=4.0.0
deprecatedThe method Apis.instance() without the second argument (auto reconnect) is deprecated. Always pass a boolean for auto reconnect.
fix
Call Apis.instance('wss://...', true) or Apis.instance('wss://...', false).
affects: >=5.0.0
gotchaThe library uses WebSocket under the hood. In browsers, the global WebSocket is used; in Node, the 'ws' package. Ensure the 'ws' package is installed if using Node <18 (it's a peer dependency but not listed in package.json).
fix
Install 'ws' as a dependency for Node <18: 'npm install ws'.
affects: *
gotchaApis.instance() must be called only once. Calling it multiple times will create multiple connections and can cause unexpected behavior.
fix
Ensure Apis.instance() is called once and reuse the promise via Apis.instance().init_promise.
affects: *
Errors
Common errors & fixes
Module not found: Can't resolve 'bitsharesjs-ws'
The package is not installed or the import path is incorrect.
fix
Run 'npm install bitsharesjs-ws' and ensure the import is correct: import { Apis } from 'bitsharesjs-ws'.
TypeError: Apis.instance is not a function
Using a default import instead of named import.
fix
Use correct import: import { Apis } from 'bitsharesjs-ws' or const { Apis } = require('bitsharesjs-ws').
Error: Can't resolve 'ws' in '/path/to/node_modules/bitsharesjs-ws/lib'
Missing peer dependency 'ws' for Node.js environments.
fix
Install the 'ws' package: 'npm install ws'.
Upgrade
Version history
6.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
bitsharesjs-ws — npm install bitsharesjs-ws · libregistry