Getting started

This section is dedicated to understanding all it takes to install and setup the PAKT SDK on your NodeJS project.

Installation

Before you can use the PAKT SDK, you need to install it by running thenpm command. To do so run:

npm install pakt-sdk

or

yarn add pakt-sdk

Get your API keys

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.

You can access your APIs or generate an API key from the API menu within Pakt's Command Center. Before attempting to access, ensure you have a paid and deployed Chainsite.

To deploy and activate a Chainsite follow this guide on Deploying a Pakt Chainsite

Initialization

To initialize, use the following code block:

import PaktSDK from "pakt-sdk";

const apiKey = config.PAKT_SDK_API_KEY;
const configData: PaktConfig = {
  token: apiKey,
  verbose: true,
};

const sdkInit = await PaktSDK.init(configData);

Make your first request

The above code initializes the PAKT SDK and ensures the API Key is generated from the Command Center.


To make calls with the PAKT SDK is very easy. See below code blocks for examples. The SDK is also typed with the models and wrapped with a default ResponseDto<T>.

ResponseDto<T> is declared as:

interface ResponseDto<T> {
  data: T;
  status: Status;
  message?: string;
  code?: string;
}

//For example, from the initialized sdk, we can login this way:

const auth: ResponseDto<UserModelDto> = await sdkInit.auth.login();

Last updated