dpos-api-wrapper
Options
All
  • Public
  • Public/Protected
  • All
Menu

npm Build Status Coverage Status

Dpos Javascript Library

Through this library you can interact with a dposAPI node in an easy way. The library works both in the browser and Node.js.

Documentation

All available methods are available in the jsdoc

Quick Start

Include the library in your browser.

Either download dist/browser/index.js or use gitcdn as follows:

<script type="text/javascript" src="https://unpkg.com/dpos-api-wrapper/dist/browser/index.js"></script>
<script>
  dposAPI.nodeAddress = 'http://example.com:5566'; // Set your node url here. (no trailing slash)

  // ...
</script>

Include it with npm (Suitable also for webpack/browserify)

npm i dpos-api-wrapper -D
var dposAPI = require('dpos-api-wrapper').dposAPI;
dposAPI.nodeAddress= 'http://example.com:5566'; // Set your node url here. (no trailing slash) 

Compatibility

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 8+ ✔

Browser Matrix

Node support

Node >= 4.x is fully supported :)

Examples

All the APIs are designed to be easy to use. You can use both Callbacks or Promises; you decide.

For example you can open a new account by doing. Be aware that all the methods sending a secret over the network are going to be deprecated:

dposAPI.accounts.open('secret', function(error, account) {
  if (!error) {
    // yay!
    console.log(account);
  } else {
    console.log('error: ', error);
  }
  // ...
});

or

dposAPI.accounts.open('secret')
    .then(function (account) {
      console.log(account);
    })
    .catch(function (error) {
      console.log('error: ', error);
    });

which can be even shorter if you write your code in TypeScript or ES6

dposAPI.accounts.open('secret')
    .then(console.log)
    .catch(error => console.log('error: ', error));

Advanced Usage

In some cases you need to connect to multiple nodes.

To do so, just use the newWrapper method:

var node1 = dposAPI.newWrapper('http://node1:1234');
var node2 = dposAPI.newWrapper('http://node2:1234');

// interact with node1 & node2 using the same APIs available within 'dposAPI' variable.

Index

Type aliases

ApiPromise

ApiPromise: Promise<T | BaseApiResponse>

MultiSigTransaction

MultiSigTransaction: BaseTransaction<T> | object

Transaction

Transaction: BaseTransaction<T> | object

cback

cback: function

Type declaration

rs

rs: function

Type declaration

    • Type parameters

      • R

      Parameters

      • obj: object
        • Optional data?: any
        • Optional headers?: any
        • Optional method?: string
        • Optional noApiPrefix?: boolean
        • Optional params?: any
        • path: string
      • cback: cback<R>

      Returns Promise<R | BaseApiResponse>

Variables

dposAPI

dposAPI: DposAPI = (() => {const toRet = {errorAsResponse: true,nodeAddress: '',newWrapper(nodeAddress: string, opts: {timeout: number, errorAsResponse?: boolean} = {timeout: 4000}): APIWrapper {const req = requester(axios, nodeAddress, {...{errorAsResponse: true}, ...opts});return addTransportBuilder({accounts : accounts(req),blocks : blocks(req),dapps : dapps(req),delegates : delegates(req),loader : loader(req),multiSignatures: multiSignatures(req),peers : peers(req),rawRequest : req,signatures : signatures(req),transactions : transactions(req),transport : transport(req),},req);},timeout: 4000,} as DposAPI;function rproxy<R>(obj: { params?: any, path: string, method?: string, data?: any }, cback: cbackType<R>): Promise<R & BaseApiResponse> {return requester(axios, toRet.nodeAddress, {timeout: toRet.timeout, errorAsResponse: toRet.errorAsResponse}).apply(null, arguments);}toRet.accounts = accounts(rproxy);toRet.loader = loader(rproxy);toRet.transactions = transactions(rproxy);toRet.peers = peers(rproxy);toRet.blocks = blocks(rproxy);toRet.signatures = signatures(rproxy);toRet.delegates = delegates(rproxy);toRet.multiSignatures = multiSignatures(rproxy);toRet.dapps = dapps(rproxy);toRet.transport = transport(rproxy);toRet.rawRequest = rproxy;return addTransportBuilder(toRet, rproxy);})()

Functions

Private accounts

addTransportBuilder

  • addTransportBuilder<T>(obj: T, rs: rsType): T | object
  • Augments the object adding a new buildTransport function

    Type parameters

    • T: object

    Parameters

    • obj: T
    • rs: rsType

    Returns T | object

Private blocks

Private dapps

Private delegates

Private loader

Private multiSignatures

Private peers

requester

  • requester(axios: AxiosStatic, nodeAddress: any, opts: object): (Anonymous function)
  • Parameters

    • axios: AxiosStatic
    • nodeAddress: any
    • opts: object
      • errorAsResponse: boolean
      • timeout: number

    Returns (Anonymous function)

Private signatures

Private transactions

transport

  • transport(rs: RsType): function