@setl/api-sdk

Library for interacting with SETL Labs instances.

Usage no npm install needed!

<script type="module">
  import setlApiSdk from 'https://cdn.skypack.dev/@setl/api-sdk';
</script>

README

SETL API SDK

The SETL API Node library provides convenient access to the SETL API from applications written in server-side JavaScript.

Documentation

See the SETL Labs API docs for more information (sign-up required).

Installation

Install the package with:

npm install @setl/api-sdk --save
# or
yarn add @setl/api-sdk

Usage

The package needs to be configured with your SETL Labs's address which is available in your SETL Labs Dashboard.

const SetlApiSDK = require('@setl/api-sdk').SetlApiSDK;
const client = new SetlApiSDK('example.setllabs.io');

const token = await client.login({
  username: 'username',
  password: 'password'
});

console.log(token);

Or using ES modules and async/await:

import { SetlApiSDK } from '@setl/api-sdk';
const client = new SetlApiSDK('example.setllabs.io');

(async () => {
  const token = await client.login({
    username: 'username',
    password: 'password'
  });

  console.log(token);
})();

Usage with TypeScript

Import SetlApiSDK as a named import and instantiate it as new SetlApiSDK(endpoint, options) with the latest API version.

import { SetlApiSDK } from '@setl/api-sdk';
const client = new SetlApiSDK('example.setllabs.io');

const getToken = async () => {
  const token = await client.login({
    username: 'username',
    password: 'password'
  });

  console.log(token);
};
getToken();

You can find a full TS server example in SETL API SDK Examples.

Configuration

Initialize with config object

The package can be initialized with several options:

import { SetlApiSDK } from '@setl/api-sdk';

const client = new SetlApiSDK('example.setllabs.io', {
    logging: false,
    memberNodePath: 'customPath/',
    port: 1234;
    walletNodePath: 'customPath/';
});
Option Default Description
logging true Use SDK internal logging of request responses.
memberNodePath /api/v3/ Custom path for membernode requests.
port 80 Port number.
walletNodePath /wn/api/ Custom path for walletnode requests.