Skip to content

ludex-sdk-js 2.0.3

Install from the command line:
Learn more about npm packages
$ npm install @ludex-labs/ludex-sdk-js@2.0.3
Install via package.json:
"@ludex-labs/ludex-sdk-js": "2.0.3"

About this version

The Official Javascript & Typescript SDK for Ludex API

Build

About

This repository contains the official Javascript & Typescript SDK for the Ludex API. For usage and documentation head over to our official documentation.

v1 Deprecation

v1 is being deprecated as now we will be doing everything via api's from now on.

Usage

Before You Begin

Make sure you have the credentials for Ludex API Services.

Organization Api key for organization scoped API's

Client Api key for client scoped API's

For further information on how to get api keys checkout our docs

Requirements

Installation

npm install @ludex-labs/ludex-sdk-js --save

or

yarn add @ludex-labs/ludex-sdk-js

Importing Ludex SDK

JavaScript:

const Ludex = require("@ludex-labs/ludex-sdk-js").Ludex;
const organizationScoped = new Ludex.OrganizationScoped(organizationApiKey);

const clientScoped = new Ludex.ClientScoped(clientApiKey);

TypeScript:

import { Ludex } from "@ludex-labs/ludex-sdk-js";
const organizationScoped = new Ludex.OrganizationScoped(organizationApiKey);

const clientScoped = new Ludex.ClientScoped(clientApiKey);

You can also pass additional options for axios:

const organizationScoped = new Ludex.OrganizationScoped(
  organizationApiKey,
  options
);

const clientScoped = new Ludex.ClientScoped(clientApiKey, options);

The options argument has the following structure:

interface AxiosOptions {
  /** Base url instead of api.ludex */
  baseUrl?: string;
  /** HTTP request timeout */
  timeoutInMs?: number;
  /** Proxy configurations */
  proxy?: AxiosProxyConfig | false;
  /** Whether to remove platform from User-Agent header */
  anonymousPlatform?: boolean;
  /** Additional product identifier to be prepended to the User-Agent header */
  userAgent?: string;
  /** Providing custom axios options including a response interceptor (https://axios-http.com/docs/interceptors) */
  customAxiosOptions?: {
    interceptors?: {
      response?: {
        onFulfilled: (
          value: AxiosResponse<any, any>
        ) => AxiosResponse<any, any> | Promise<AxiosResponse<any, any>>;
        onRejected: (error: any) => any;
      };
    };
  };
}

Axios Interceptor

You can provide the sdk options with an axios response interceptor:

new Ludex.OrganizationScoped(organizationApiKey, {
  customAxiosOptions: {
    interceptors: {
      response: {
        onFulfilled: (response) => {
          return response;
        },
        onRejected: (error) => {
          throw error;
        },
      },
    },
  },
});

Error Handling

The SDK throws AxiosError upon http errors for API requests.

You can read more about axios error handling here.

You can get more data on the Ludex error using the following fields:

  • error.response.data.code: The Ludex error code (HTTP code)
  • error.response.data.message: Explanation of the Ludex error

Response Handling

The SDK returns an AxiosResponse upon successful API requests.

{
  "data": {},
  "status": 200,
  "statusText": "OK",
  "headers": {},
  "config": {},
  "request": {}
}

For example, to get a challenge you can do the following:

import { Ludex } from "@ludex-labs/ludex-sdk-js";
const ludexClientApi = new Ludex.ClientScoped(clientApiKey);
const challengeId = 1;
const response = await ludexClientApi.getChallenge(challengeId);
const challenge = response.data;

The challenge object should have the following structure:

{
  "id": 1,
  "limit": 2,
  "state": "LOCKED",
  "blockchainAddress": "0x000000",
  "payout": {
    "id": 1,
    "entryFee": 3000000,
    "mediatorRake": 100000,
    "providerRake": 200000,
    "chain": "SOLANA",
    "uiValues": {
      "entryFee": 0.003,
      "mediatorRake": 0.0001,
      "providerRake": 0.0002
    }
  },
  "players": ["0x000000", "0x000000"],
}

Details


Assets

  • ludex-sdk-js-2.0.3.tgz

Download activity

  • Total downloads 1
  • Last 30 days 0
  • Last week 0
  • Today 0