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

@wandevs/iwan-sdk

v1.7.1

Published

JavaScript SDK for iWan RPC Server

Downloads

147

Readme

iwan-js-sdk

GitHub License

JavaScript SDK for iWan RPC Server

Install

Use NPM or Yarn to install the library:

npm install --save iwan-sdk

Config

After installation, the iWan SDK can be used to connect to the iWan RPC server to call a method such as getBalance. The default config can be used or custom config parameters can be passed using the option object.

const iWanClient = require('iwan-sdk');

By default the SDK will connect to "api.wanchain.org:8443"

let apiClient = new iWanClient(YourApiKey, YourSecretKey);

A different URL can be specified in the option object which is subject to iWan.


//Subject to https://iwan.wanchain.org
let option = {
    url:"apitest.wanchain.org",
    port:8443,
    flag:"ws",
    version:"v3",
    timeout:300000
};
apiClient = new iWanClient(YourApiKey, YourSecretKey, option);

Th client should be closed after all operations.

apiClient.close();

Instead of using the iWan SDK for connecting to the iWan RPC server, a raw WebSocket API can also be used, for more information, please see the documentation iWan RPC API. However, we strongly recommend using the iWan SDK.

Details about option

The SDK object can accept an option object. See below for examples of usage.

  • option {Object}
    • url {String} The RPC server URL, default is 'api.wanchain.org'.
    • port {Number} The RPC server port, default is 8443.
    • flag {String} The flag to connect the iWan RPC server, default is 'ws'.
    • version {String} The RPC method version, default is 'v3'.
    • timeout {Number} The RPC method timeout, default is 30000 (ms).

ApiKey and SecretKey

In order to get an ApiKey, sign up at iWan. Then create a new project to get a new ApiKey and SecretKey key pair.

Basic Usage

Both Promise and callback are supported for each method.

  • callback {Function}
    • err {String} in case of error, error details will be stored in err, err will contain null otherwise.
    • result {Object} if successful (in other words err is null), the result object will contain the result of the method called, such as getBalance.

The method getBalance is used as an example below to show the use of callback and Promise in the iWan SDK :

Callback

callback can be used for asynchronous mode:

apiClient.getBalance('WAN', '0x0cc79fa3b80c5b9b02051facd02478ea88a78e2c', (err, balance) => {
  if (err) {
    console.log(err);
  } else {
    console.log("Balance result is ", balance);
  }
});

Promise

Promise can be used for synchronous mode:

try {
  let balance = await apiClient.getBalance('WAN', '0x0cc79fa3b80c5b9b02051facd02478ea88a78e2c');
  console.log("Balance result is ", balance);
} catch (err) {
  console.log(err);
}

Examples

Development

  1. git clone https://github.com/wanchain/iWan-js-sdk.git
  2. npm install
  3. npm test

Documentation

iWan SDK API : API details about iWan SDK