Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonustrack/kbyte
A lightweight JavaScript library for Obyte
https://github.com/bonustrack/kbyte
byteball kbyte obyte websocket ws
Last synced: 4 days ago
JSON representation
A lightweight JavaScript library for Obyte
- Host: GitHub
- URL: https://github.com/bonustrack/kbyte
- Owner: bonustrack
- License: wtfpl
- Created: 2017-10-21T20:50:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T20:00:17.000Z (5 months ago)
- Last Synced: 2024-10-18T07:23:43.709Z (19 days ago)
- Topics: byteball, kbyte, obyte, websocket, ws
- Language: TypeScript
- Homepage: https://bonustrack.gitbook.io/kbyte
- Size: 680 KB
- Stars: 14
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/kbyte.svg)](https://www.npmjs.com/package/kbyte)
[![Try kbyte on RunKit](https://badge.runkitcdn.com/kbyte.svg)](https://runkit.com/bonustrack/kbyte)# kbyte.js
A lightweight JavaScript library for Obyte
### Install
kbyte was designed to work both in the browser and in Node.js.#### Node.js
To install kbyte on Node.js, open your terminal and run:
```
npm install kbyte
```#### Browser
You can create an index.html file and include kbyte with:
```html```
### Usage
```js
var kbyte = require('kbyte');// Init WebSocket client
var client = new kbyte.Client('wss://obyte.org/bb');// Get peers
client.request('get_peers', null, function(err, result) {
console.log(err, result);
});
```
[See more examples](/test/test.ts)### Promises
You can also use kbyte with promises by promisifying kbyte with
[bluebird](https://github.com/petkaantonov/bluebird) as in:```js
var kbyte = require('kbyte');
bluebird.promisifyAll(kbyte.Client.prototype);
```It'll add a *Async* to all kbyte functions (e.g. return client.requestAsync().then())
client.request('get_peers', null, function(err, result) {
console.log(err, result);
});
```js
// So instead of writing client.request('get_peers', null, cb); you have to write:
client.requestAsync('get_peers', null).then(function(result) {
console.log(result); // => ['wss://byteroll.com/bb', 'wss://byteball.fr/bb' ...]
});
```### License
[MIT](LICENSE).