Immutable X SDK

Overview

An introduction to the SDK can be found in the Immutable X SDK section.

Link Usage

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

async function sdkExample() {
    const link = new Link('https://link.ropsten.x.immutable.com');

    // Register user, you can persist address to local storage etc.
    const { address } = await link.setup({});
    localStorage.setItem('address', address);

    // Deposit ETH into IMX
    link.deposit({
        type: ETHTokenType.ETH,
        amount: '0.01',
    });

    // View transaction history
    link.history({});

    // Create a sell order for token id 123 for 0.01 ETH
    link.sell({
        amount: '0.01',
        tokenId: '123',
        tokenAddress: '0x2ca7e3fa937cae708c32bc2713c20740f3c4fc3b',
    });

    // Create a buy flow:
    link.buy({
        orderIds: ['1', '2', '3'],
    });

    // Prepare withdrawal, you will need to wait some time before completing the withdrawal
    link.prepareWithdrawal({
        type: ETHTokenType.ETH,
        amount: '0.01',
    });

    // Complete withdrawal
    link.completeWithdrawal({
        type: ETHTokenType.ETH,
    });
}

API Client Usage

The API client is basically a direct mapping to the REST methods which you can see at https://docs.x.immutable.com/reference. Please refer to this document for all the options available.

import { ImmutableXClient } from '@imtbl/imx-sdk';

async function libExample() {
    const client = await ImmutableXClient.build({ publicApiUrl: 'https://api.ropsten.x.immutable.com' });
    const address = localStorage.getItem('address');

    if (address) {
        const balances = await client.getBalances({ user: address });
        const orders = await client.getOrders();
        const order = await client.getOrder({ orderId: 1 });
        const assets = await client.getAssets({
            user: address,
        });
    }
}

Did this page help you?