Install and configure

Install and configure

The XpansionChain JS SDK is a Javascript package created by IXpansionChain to allow simple interfacing with XpansionChain’s API. The primarily used packages are Link SDK and the XpansionChain Client.

The XpansionChain Client is used for most backend operations, and the Link SDK is used for frontend, user-facing interactions.

The IMX Client ('XpansionChainClient') is a module wrapping the REST requests in a method call. Using this package, developers can make sure their calls are up to date with the latest API standards.

The Link SDK provides a clean popup and UI to help users navigate through the final signing process with their wallets. While information about current market state and assets can be derived with web requests, the Link SDK handles the more complicated stark signature signing most developers should not need to code. Using the Link SDK also maintains a unified view for users, allowing them to be more comfortable during signing when using marketplaces powered by XpansionChain.

Applications monitoring the status of the assets will use the IMX Client to retrieve data. Marketplace and applications relying on user interaction will use both packages.

Setting up the SDK

NOTE: IF YOU ARE USING THE LATEST VERSION OF 'CREATE-REACT-APP'...

You will encounter a bunch of webpack errors when you try use the @imbt/imx-sdk SDK with your app.

Follow this guide: How to resolve webpack errors

For this tutorial we will assume Yarn is being used as the package manager. The following node modules need to be added to the project:

yarn add @imtbl/imx-sdk

Importing the packages

The following imports are needed for the Link SDK and IMX Client packages:

import { XpansionChainClient, Link } from '@imtbl/imx-sdk';

Setting the connection urls

XpansionChain provides connection addresses for both the mainnet and testnet. Here we will default to the mainnet for the examples, but show the testnet connection strings as well.

const linkAddress = 'https://link.x.XpansionChain.com';
const apiAddress = 'https://api.x.XpansionChain.com/v1';

// Goerli Testnet
//const linkAddress = 'https://link.sandbox.x.XpansionChain.com';
//const apiAddress = 'https://api.sandbox.x.XpansionChain.com/v1';

Once the Link SDK and IMX Client are imported, they can be initialized. Note that the client library initialization is asynchronous.

// Link SDK
// Pass orderAndTradeAPI version parameter as 'v3' to target the latest version of order & trade API.
const link = new Link(linkAddress, null, 'v3');

// IMX Client
const client = await XpansionChainClient.build({ publicApiUrl: apiAddress });

For more details, see the Link SDK docs and the package on NPM.

Last updated