Setup
Learn how to set up your environment to integrate and use Immutable Orderbook
Install
Prerequisites
Node Version 20 or later
To install nvm
follow these instructions. Once installed, run:
nvm install --lts
- (Optional) To enable Code Splitting (importing only the SDK modules you need) there are additional prerequisites.
Install the Immutable SDK
Run the following command in your project root directory.
- npm
- yarn
npm install -D @imtbl/sdk
# if necessary, install dependencies
npm install -D typescript ts-node
yarn add --dev @imtbl/sdk
# if necessary, install dependencies
yarn add --dev typescript ts-node
The Immutable SDK is still in early development. If experiencing complications, 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 install
Initialize
When you initialize the SDK, the chainName configuration will direct the SDK to connect to a specific environment.
Supported values are:
Chain Name | Chain ID | Operator Allowlist Address |
---|---|---|
imtbl-zkevm-testnet | eip155:13473 | https://api.sandbox.immutable.com/v1/chains returns operator_allowlist_address |
imtbl-zkevm-mainnet | eip155:13371 | https://api.immutable.com/v1/chains returns operator_allowlist_address |
import { config, orderbook } from '@imtbl/sdk';
const PUBLISHABLE_KEY = 'YOUR_PUBLISHABLE_KEY'; // Replace with your Publishable Key from the Immutable Hub
const client = new orderbook.Orderbook({
baseConfig: {
environment: config.Environment.SANDBOX,
publishableKey: PUBLISHABLE_KEY,
},
});
Create signers for user authorisation
Creating, filling and cancelling orders require a user's authorisation.
A signer is a representation of a user's wallet (account) that is used to authorise transactions. These transactions typically involve transferring the ownership of assets (currencies or NFTs) from one account to another, hence why the user is required to "sign" these transactions. Applications use signers to obtain user signatures to execute payments, asset transfers, and more. For more information, see the Signers definition from the ethers
library.
- Passport
- Browser
- Private key
To initialise the passport
module, please see the Passport Setup guide.
import { BrowserProvider } from "ethers"; // ethers v6
const passportWallet = await passport.connectEvm(); // returns an EIP-1193 provider
const ethersProvider = new BrowserProvider(passportWallet);
const signer = await ethersProvider.getSigner();
import { BrowserProvider } from "ethers"; // ethers v6
import CodeBlock from '@theme/CodeBlock';
const browserWallet = new BrowserProvider(window.ethereum);
Then, create a signer from the wallet connection:
const signer = await browserWallet.getSigner();
import { getDefaultProvider, Wallet } from "ethers"; // ethers v6
const rpcProvider = getDefaultProvider("https://rpc.testnet.immutable.com/")
const signer = new Wallet(PRIVATE_KEY, rpcProvider);