npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dashevo/dapi-sdk

v1.2.0

Published

Client SDK for DASH DAPI.

Downloads

14

Readme

Note on software compatibility:

This package requires the use of Node >= 8.0.0 and is broadly compatible with modern browsers implementing the ECMAScript 2015 standard or better.

Table of Content

Features :

  • Deliver a bitcore-wallet-service compatible D-API (see BWS doc here).
  • Provide accounts registration/authentication (using OP_RETURN for now).
  • Basic discovery mode and request balancing.
  • Explorer API (connector with Insight-API)
  • Blockchain/SPV validation (blockheaders)
  • TX/Blocks events (whenever a new block/tx is found emit the data).

Getting Started

Install DAPI-SDK

  • npm : npm i -S dapi-sdk
  • github : npm i -S github:dashevo/dapi-sdk

Uses :

You can check our test folder to see some usage exemples.

Import the package :

//import package
const DAPISDK = require('dapi-sdk');

//Quiter version of possibles options.
const options = {
    debug:false,
    verbose:false,
    errors:false,
    warnings:false
};
let SDK = DAPISDK(options);

Where theses options can be (in parenthesis,the default value) :

  • debug(false) : Bool - When activated, returns utils logs (methods called, uris...)
  • verbose(false) : Bool - Will talk. A lot. Emitted events, received stuff...
  • warnings(true) : Bool - When activated, log errors received/handled.
  • errors(true) : Bool - When activated, log errors received/handled.
  • DISCOVER: Object -
    • INSIGHT_SEEDS : Array of insight-api uri metadata endpoints (temporary step - see below an exemple)
{
"INSIGHT_SEEDS": [
           {
                "protocol": "http",
                "path": "insight-api-dash",
                "base": "51.15.5.18",
                "port": 3001
            }
        ]
}

Most of the SDK methods will returns you a Promise.

Therefore depending on your specific needs you can init or call methods of the SDK in a async way :

let API = SDK.Explorer.API;

API
	.getLastBlockHeight()
	.then(function (height) {
        console.log(`last height is ${height}`);
    })

API
	.getLastBlockHeight(API.getHashFromHeight)
	.then(function(hash){
		console.log(`Last hash is ${hash}`);
	})
});

or using async/await features provided in last NodeJS version :

let height = await SDK.Explorer.API.getLastBlockHeight();
console.log(`last height is ${height}`);

On the API documentation below, and for readability reasons, await will mostly be used.

Add specific insight-api node

During developement phase, you might need to have access to the website you want to call your data from. Therefore you have the possibility to add your seed yourself (we might bring default stable server later).

Exemple :

const options = {
   STUFF:stuff,
   DISCOVER:{
           INSIGHT_SEEDS:[{
               protocol:"https",
               path:'api',
               base:"insight.dash.siampm.com",
               port: 443
           }]
       }
};
let SDK = await DAPISDK(options);

API Documentation :

Components :

After having initiate DAPI-SDK, you will then have access to differents components (à-la framework).

  • Explorer will allow you to perform some command on the Insight-API of a masternode (chosen randomnly on a validated list). As it will use some Discover methods in order to get the Insight Candidate, calling an Explorer call will first perform an init of Discover (and therefore will fetch and validate the list) before returning the value. Make a note that this will be performed only once.

  • Blockchain will allow you to have access to some components such as : getting an object stored in your in-mem db, or validate multiple blocks, calculate the next difficulty. The initialization must be done by yourself using : await SDK.Blockchain.init() in order to beneficiate theses function. Make note that by default it will connect to a randomnly selected insight-api by websocket and will listen to all block. When a block is emitter by the API, it will add it in the blockchain. This comportement can be disable by passing to init the corresponding options (see below). Using SDK.Blockchain.chain enable you to use the blockchain-spv-dash methods

  • tools will allow to access to some of the dependencies of the SDK. Most notably, you have access to :

    • SDK.tools.util which correspond to a library of handy stuff such as toHash(hex), compressTarget, expandTarget. API here : dash-util
    • SDK.tools.bitcore which correspond to a library used in insight-api, see API here : bitcore-dash-library. Contains elements that allow to generate address, sign/verify a message...