Skip to content


Folders and files

Last commit message
Last commit date

Latest commit


Repository files navigation


GitHub License

JavaScript SDK for iWan RPC Server


Use NPM or Yarn to install the library:

npm install --save iwan-sdk


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 ""

let apiClient = new iWanClient(YourApiKey, YourSecretKey);

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

//Subject to
let option = {
    url:"", // for mainnet use -->
apiClient = new iWanClient(YourApiKey, YourSecretKey, option);

Th client should be closed after all operations.


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 ''.
    • 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 can be used for asynchronous mode:

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


Promise can be used for synchronous mode:

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



  1. git clone
  2. npm install
  3. npm test


iWan SDK API : API details about iWan SDK