slpclient
v1.0.48
Published
Connect to the SLP world (socket and HTTP)
Downloads
4
Readme
SLPClient
A library for interacting with SLPDB from a browser or server, with BitDB API calls wrapped into lexical endpoints.
Please see the sidebar on the left of the documentation for method calls. Please feel free to contribute your own method calls whenever you want.
Installation
npm install --save slpclient
This module was built using Node v8.14.0
Basic Usage
var slpclient = new SLPClient(httpURL,socketURL);
// Get the token info for a genesis tx:
var tokenInfo = await slpclient.getInfo(tokenId);
Advanced Features (Cascade)
Most cryptocurrency libraries today are more difficult than they need to be. Traditional requests are generally easier to test, so they're done first. WebSocket requests are harder to test, but have the advantage of always giving you the most recent data as it comes in. Generally, a real-time web developer will use both these types of requests in their code to get the intitial data, then update the data as it comes in. SLPClient aims to do this for you automatically, using a .live()
chain variable. Traditional requests are available with a .get()
chain, and websocket requests are available with the .on()
chain.
For example. You can access a given data (e.g. info
)in three different ways:
slpclient.info(tokenId).get()
will make an HTTP request to get the latest balance.slpclient.info(tokenId).on(callback)
fires a callback with the latest Websocket data as it comes inslpclient.info(tokenId).live()
is a combination of .get() and .on(), which first performs an HTTP request, then updates its response with the latest data from the WebSocket. This function returns apointer
to an object containing the latest data. To access the value, chain.is
to the return value.
So, instead of firing a callback, the .live()
variable allows your object to have a key which always refreshes with the latest value. This should produce much cleaner and simpler code.
var x = {};
x.tokenInfo = await slpclient.info(tokenId).live();
console.log(x.tokenInfo.is) // .is contains the latest value
If you don't want to use chaining, you can always access this data traditionally too (e.g. slpclient.getInfo
and slpclient.onAllAddressesWithToken
)
Test
A good way to get started is to run the in-browser tests.
npm run hot
Serverside-validation
Under the hood, SLPClient is using MongoDB queries to access SLPDB on a remote server. Since any MongoDB query can be written (like a loop or really big query), this provides an abusive level of power to the client.
To avoid this abuse, SLPClient adds its lexical function calls to the JSON query sent to the server. These function calls (e.g. .history(simpleledger:qrqfrqwofeqwefqwff)
) can be used to 'regex' the query on the server side before sending it to SLPDB. This does make the 'raw' query function irrelevant. This is available in the ./server/ directory.
The server in the ./server/ directory