Giter VIP home page Giter VIP logo

bitsharesjs-ws's Introduction

Bitshares websocket interface (bitsharesjs-ws)

Pure JavaScript Bitshares websocket library for node.js and browsers. Can be used to easily connect to and obtain data from the Bitshares blockchain via public apis or local nodes.

Credit for the original implementation goes to jcalfeee.

npm version npm downloads

Setup

This library can be obtained through npm:

npm install bitsharesjs-ws

Usage

Several examples are available in the /examples folder, and the tests in /test also show how to use the library.

Browser bundles are provided in /build/, for testing purposes you can access this from rawgit:

<script type="text/javascript" src="https://cdn.rawgit.com/bitshares/bitsharesjs-ws/build/bitsharesjs-ws.js" />

A variable bitshares_ws will be available in window.

For use in a webpack/browserify context, see the example below for how to open a websocket connection to the Openledger API and subscribe to any object updates:

var {Apis} = require("bitsharesjs-ws");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
    console.log("connected to:", res[0].network);
    Apis.db.set_subscribe_callback( updateListener, true )
});

function updateListener(object) {
    console.log("set_subscribe_callback:\n", object);
}

The set_subscribe_callback callback (updateListener) will be called whenever an object on the blockchain changes or is removed. This is very powerful and can be used to listen to updates for specific accounts, assets or most anything else, as all state changes happen through object updates. Be aware though that you will receive quite a lot of data this way.

Witness node endpoints

This is a non-exhaustive list of endpoints available from the witness_node executable, which provides the API server of Bitshares.

Public API

Please see all available methods in the official documentation.

Database API

To access the Database API, you can use the Apis.db object.

Usage example Apis.db.get_objects(["1.3.0", "2.0.0", "2.1.0"])

History API

To access the Account History API, you can use the Apis.history object.

Usage example Apis.history.get_account_history("1.2.849826", "1.11.0", 10, "1.11.0")

Tests

The tests show several use cases, to run, simply type npm run test. The tests require a local witness node to be running, as well as an active internet connection.

bitsharesjs-ws's People

Contributors

abitmore avatar calvinfroedge avatar clockworkgr avatar dependabot[bot] avatar hldzlk avatar pluswave avatar scientistnik avatar sschiessl-bcp avatar svk31 avatar xiangxn avatar youaresofunny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitsharesjs-ws's Issues

Installation on Windows

Hi,

I try to install your project on my computer, I am following your instructions :

npm install bitsharesjs-ws

Then I am doing :

yarn install
yarn install v1.6.0
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

info Lockfile not saved, no dependencies.
Done in 0.03s.

No files are saved.

If I download directly from GitHub and I do :

yarn
yarn install v1.6.0
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
warning [email protected]: ๐Ÿ™Œ  Thanks for using Babel: we recommend using babel-preset-env now: please read bab
eljs.io/env to update!
warning mocha > glob > [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
warning mocha > [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
warning mocha > [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
[3/5] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
[5/5] Building fresh packages...
success Saved lockfile.
$ npm run build
[#############################################################------------------------------------------------] 364/652
> [email protected] prebuild C:\Users\
> npm run clean


> [email protected] clean C:\Users\
> rm -rf ./cjs/* & rm -rf ./build/* & rm -rf ./es/*


> [email protected] build C:\Users\
> BABEL_ENV=cjs babel lib --out-dir cjs

'BABEL_ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `BABEL_ENV=cjs babel lib --out-dir cjs`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!    
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

if I change :
BABEL_ENV=cjs babel lib --out-dir cjs

By :
SET BABEL_ENV=cjs babel lib --out-dir cjs

I have no more error but nothing is build.
I just want to use cjs to run the example api.js

Thanks

Manager check connections -> 0 invalid -> multiple unreachable?

Anyone experience any issues with Manager.checkConnections()?

All 7 nodes for me will pass, but then when I try to connect immediately after lag checking several of the nodes will timeout.

Are these ws servers potentially blocking my ip if I'm connecting shortly after a connection check? Or perhaps the ws connections aren't closing properly or are lingering, causing later connection issues?

Trying to add the node lag checks to beet, but it's got to cycle through multiple bad (passed) nodes before working..

Cannot run postbrowserify script because of missing Uglify.js

  1. clone repository
  2. npm install

result:

npm WARN deprecated [email protected]: uglifyjs is deprecated - use uglify-js instead.

...

[email protected] postbrowserify /home/ppitonak/workspace/bitsharesjs-ws
> NODE_ENV=production uglifyjs --compress --mangle --sequences --drop_console --mangle-props --screw-ie8 --output build/bitsharesjs-ws.min.js -- build/bitsharesjs-ws.js

sh: uglifyjs: command not found

uglifyjs binary is not in node_modules/.bin

Solution:

  • change uglifyjs in package.json to uglify-js

Terminating a ws connection takes forever, why?

I am testing new reconnection strategy for UI and I found that it takes forever when ChainWebSocket recognizes that connection is dead until the rpc_connection_status in BlockchainStore is updated.

Why is that @svk31 ? You can test it by simply opening the UI and disabling the internet connection after connection has been established. Are there any timeouts involved that are possibly to high?

image

Uglifying bitsharesjs-ws

@scientistnik

Have you tried to uglify your refactored version (needed when being included in bitsharesjs)? It fails on my end, do you have any pointers?

cross-env NODE_ENV=production uglifyjs --compress --mangle --sequences --drop_console --output build/bitsharesjs-ws.min.js -- build/bitsharesjs-ws.js

Documentation?

Is there any documentation on how to use this package?
Please note that there's no option for posting issues on the package bitsharesjs

npm run build on Win10

Got the following error:

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prebuild: npm run clean
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prebuild script 'npm run clean'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bitsharesjs-ws package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run clean

Why commented short Apis call?

Why this commented?
https://github.com/bitshares/bitsharesjs-ws/blob/master/lib/src/ApiInstances.js#L75-L79

// db: (method, ...args) => Apis.instance().db_api().exec(method, toStrings(args)),
// network: (method, ...args) => Apis.instance().network_api().exec(method, toStrings(args)),
// history: (method, ...args) => Apis.instance().history_api().exec(method, toStrings(args)),
// crypto: (method, ...args) => Apis.instance().crypto_api().exec(method, toStrings(args))
// orders: (method, ...args) => Apis.instance().orders_api().exec(method, toStrings(args))

require('../cjs) in examples

Hi. I am having trouble running the accountIteration.js example because the require('../cjs') statement cannot find the cjs file and I see it is in the .gitignore file from when I cloned the repo. Anyway I can get access to this file so I can run the code?

Thank You
-Ben

Code Problem

I cannot understand how can you send message from client to server by WebSocket in ChainWebSocket.js.
And why you set the following variable quantity
this.send_life & this.recv_life
this.current_reject
this.keepalive_timer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.