For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quick start

To install and run Obyte.js, follow this quick start guide.

Install

Obyte.js was designed to work both in the browser and in Node.js.

Node.js

To install Obyte.js on Node.js, open your terminal and run:

npm i obyte --save

Browser

You can create an index.html file and include Obyte.js with:

<script src="https://cdn.jsdelivr.net/npm/obyte"></script>

Usage

Ways to initiate WebSocket client:

const obyte = require('obyte');

// Connect to mainnet official node 'wss://obyte.org/bb'
const client = new obyte.Client();

// Connect to a custom node
const client = new obyte.Client('wss://relay.bytes.cash/bb');

// Connect to testnet
const options = { testnet: true };
const client = new obyte.Client('wss://obyte.org/bb-test', options);

Available client options:

Option
Default
Description

testnet

false

connect to testnet

reconnect

false

automatically reconnect (one attempt per second) after the connection drops

closeIfError

false

close on the first connection error instead of reconnecting

Connection lifecycle

onConnect fires on every successful connection — including every reconnection when reconnect: true is set. Notification subscriptions live for a single connection by design, so register them inside onConnect to have them set up again after every reconnect:

Unlike subscribe, the heartbeat timer belongs outside onConnect: one timer per client, not per connection. Heartbeats are skipped automatically while the connection is down (and while there is recent traffic), whereas a timer registered on every reconnection would pile up duplicates. Call clearInterval once you are done with the client.

Close the client:

With reconnect: true the client treats a closed socket as a dropped connection and reconnects even after an intentional close(). To close such a client permanently, disable reconnection first:

All API methods follow this pattern:

Transaction

To compose and post unit you need first to create a Obyte wallet and fund it with the native currency ‘bytes’. The generated WIF will be used on Obyte.js. Click on the link below to learn more:

Generate a random address

Sending a payment:

Migration to 0.2.0

0.2.0 modernizes the internals (updated dependencies, pure-JS crypto, a much smaller browser bundle) and is backward compatible for normal use — addresses, signatures and WIF keys are byte-for-byte identical, and messages signed by older versions still validate (and vice-versa). There is one breaking change to watch for.

utils.fromWif().privateKey is now a Uint8Array (was a Buffer)

The bytes are exactly the same — only the type changed, so Buffer-specific methods behave differently:

If your code consumed the private key as a Buffer, wrap it once:

Everything else is unchanged. utils.toWif() and utils.signMessage({ privateKey }) still accept both Buffer and Uint8Array, so passing a Buffer keeps working.

Last updated