Skip to main content

Typescript SDK

This SDK provides access to a wide range of features allowing you to integrate your game with key blockchain functionality.

💡Rollups this SDK supports


Installation

Prerequisites

Node version

The Immutable SDK requires Node v18 (Active LTS version) or higher. Node v18 can be installed via nvm which allows to quickly install and use different versions of node via the command line.

The installation steps for nvm for Linux, Mac, and Windows Install & Update Script. You are now ready to install the Node LTS version:

nvm install --lts

Install the Immutable SDK

Run the following command in your project root directory.

npm install -D @imtbl/sdk
Troubleshooting

The Immutable SDK is still in early development. Should complications arise during the installation, please use the following commands to ensure the most recent release of the SDK is correctly installed:

rm -Rf node_modules
npm cache clean --force
npm i

Dependencies

npm install -D typescript ts-node

Initialization

Each module of the Immutable SDK must be initialised with an instance of an ImmutableConfiguration. The ImmutableConfiguration defines configuration that is shared across modules, such as the current environment. An instance of an ImmutableConfiguration can be initialised as follows:

import { config } from '@imtbl/sdk';

const baseConfig = new config.ImmutableConfiguration({
environment: config.Environment.PRODUCTION,
});
💡Environments

The environment argument can be one of the following:

Environment ConfigurationDescription
Environment.SANDBOXThe default test network (currently, it is Goërli)
Environment.PRODUCTIONThe Ethereum mainnet network

SDK modules can then be initialised as follows:

import { passport, provider } from '@imtbl/sdk';

const passport = new passport.Passport({
baseConfig,
// Passport specific configuration
});

const provider = new provider.GenericIMXProvider({
baseConfig,
// Provider specific configuration
});

Browser Bundle

Our SDK is available publicly, and therefore there are a few services that you can use to serve the browser bundle to your webpage:

Both services allow specifying versions of the SDK to use, so if you want a specific version, with levels of specificity. For example:

  • If you want a specific version (0.20.1), specify it fully.
    • https://cdn.jsdelivr.net/npm/@imtbl/sdk@0.20.1
  • If you want a minor version:
    • https://cdn.jsdelivr.net/npm/@imtbl/sdk@0.20
  • If you want to support a major version:
    • https://cdn.jsdelivr.net/npm/@imtbl/sdk@0

You can load the script directly in your webpage, like any other script tag, for example:

<script src="https://cdn.jsdelivr.net/npm/@imtbl/sdk@0.20.1"></script>

Once loaded, you can access the immutable SDK via the window.immutable object.

Browser bundle in console

From there, please look at each product's documentation on how to use each of the available modules.

Code Splitting

The Immutable SDK is designed to be used in a code-splitting environment, such as a web browser.

Your project will need some specific configuration to enable code splitting:

  • Typescript version 5 or higher
  • TS Config needs to have compilerOptions.moduleResolution set to bundler
  • Your code editor and project should have the same version of Typescript
// old import method
import { config } from '@imtbl/sdk';
const env = config.Environment.SANDBOX;

// new import method with code-splitting
import { Environment } from '@imtbl/sdk/config';

Further documentation