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:
1
npm i obyte --save
Copied!

Browser

You can create an index.html file and include Obyte.js with:
1
<script src="https://cdn.jsdelivr.net/npm/obyte"></script>
Copied!

Usage

Ways to initiate WebSocket client:
1
const obyte = require('obyte');
2
3
// Connect to mainnet official node 'wss://obyte.org/bb'
4
const client = new obyte.Client();
5
6
// Connect to a custom node
7
const client = new obyte.Client('wss://relay.bytes.cash/bb');
8
9
// Connect to testnet
10
const options = { testnet: true };
11
const client = new obyte.Client('wss://obyte.org/bb-test', options);
Copied!
Close the client:
1
client.close();
Copied!
All API methods follow this pattern:
1
// If the last argument is a function it is treated as a callback
2
client.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=', function(err, result) {
3
if (err) return console.error(err);
4
console.log(result);
5
});
6
7
// If a callback is not provided, a Promise is returned
8
client.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=')
9
.then(function(result) {
10
console.log(result);
11
})
12
.catch(function(err) {
13
console.error(err);
14
});
Copied!

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:
Sending a payment:
1
const wif = '5JBFvTeSY5...'; // WIF string generated (private key)
2
3
const params = {
4
outputs: [
5
{
6
address: 'NX2BTV43XN6BOTCYZUUFU6TK7DVOC4LU', // The Obyte address of the recipient
7
amount: 1000 // The amount he receives
8
}
9
]
10
};
11
12
client.post.payment(params, wif, function(err, result) {
13
if (err) return console.error(err);
14
console.log(result); // The unit hash is returned
15
});
Copied!
Last modified 4mo ago
Copy link