Typescript SDK
This SDK provides access to a wide range of features allowing you to integrate your game with key blockchain functionality.
Installation
Prerequisites
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
- yarn
npm install -D @imtbl/sdk
yarn add --dev @imtbl/sdk
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:
- npm
- yarn
rm -Rf node_modules
npm cache clean --force
npm i
rm -Rf node_modules
yarn cache clean
yarn
Dependencies
- npm
- yarn
npm install -D typescript ts-node
yarn add --dev 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,
});
The environment
argument can be one of the following:
Environment Configuration | Description |
---|---|
Environment.SANDBOX | The default test network (currently, it is Goërli) |
Environment.PRODUCTION | The 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:
- jsdelivr (https://cdn.jsdelivr.net/npm/@imtbl/sdk)
- unpkg (https://unpkg.com/@imtbl/sdk)
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.
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 tobundler
- 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
- See the Developer homepage for general information on building on Immutable.
- Build on Immutable zkEVM:
- Build on Immutable X: