Skip to main content

Install and initialize

Overview

This guide shows how to install and initialize Lockbox SDK for your platform. The SDK enables you to integrate MPC (multi-party computation) features into your browser game or Unity project.

The implementation steps differ slightly between browser games and games built with Unity. The following tabs provide platform-specific instructions:

  • The Web tab covers the use of the Lockbox provider in the MPC JavaScript SDK and is meant for beginner web3 developers who wish to implement the essential MPC features.
  • The Unity tab contains the instructions and code examples for Unity developers integrating their blockchain-enabled games with Lockbox.

Prerequisites

  • Complete the steps in Get started.
  • Install the dependencies:
    • Node.js v18.16 or later
    • npm or Yarn for package installation

Steps

Step 1. Install the SDK

Install the Lockbox JS SDK using npm:

npm install @axieinfinity/lockbox@2.1.0

Or using Yarn:

yarn add @axieinfinity/lockbox@2.1.0

Step 2. Initialize the SDK

  1. Import the Lockbox package:
import { Lockbox } from "@axieinfinity/lockbox";
  1. Initialize Lockbox:
import { Lockbox } from "@axieinfinity/lockbox";

export const lockbox = Lockbox.init({
chainId: `${BLOCKCHAIN_CHAINID}`, // Blockchain network chain ID
accessToken : `${YOUR_ACCESS_TOKEN}`, // User's access token, can be set later
serviceEnv: 'stag' OR 'prod', // Staging or production environment
wasmParams: {
trackParams: {
enable: boolean, // Whether to enable data tracking
timeout: 3, // Timeout for data tracking API
},
timeout: 20, // Timeout for SDK call to the server
optionalParams: '{"enableVerboseLog":false}', // Whether to enable verbose logging
}

})

Parameters:

NameTypeRequiredDescription
chainIdNumberRequiredChain ID of the blockchain network to interact with: 2020 for the Ronin mainnet and 2021 for the Saigon testnet. The default is 2020.
overrideRpcUrlStringOptionalRPC (remote procedure call) URL of the blockchain network. Must correspond to the specified chainId.
accessTokenStringOptionalOAuth access token.
serviceEnvStringOptionalThe server environment to connect to: prod for production and stag for staging. The default is stag.
wasmParamsWasmParamsOptionalConfiguration for Sky Mavis's data tracking SDK. Enabled by default.

Example:

import { Lockbox } from "@axieinfinity/lockbox";

export const lockbox = Lockbox.init({
chainId: 2021, // Saigon testnet
serviceEnv: "stag", // Staging environment
});
///...
caution

To get Lockbox ready, make sure to set the access token and client shard.

  1. Set the access token after authentication:
const accessToken = `${YOUR_ACCESS_TOKEN}`;
lockbox.setAccessToken(accessToken);
  1. Set the client shard after generating the key or decrypting:
const clientShard = `${YOUR_CLIENT_SHARD}`;
lockbox.setClientShard(clientShard);

Next steps

Create a wallet