Install and initialize
Overview
This guide shows how to install and initialize the MPC (multi-party computation) SDK for your platform. The SDK enables you to integrate MPC features into your web or Unity game, such as creating wallets, signing messages, and more.
The implementation steps differ slightly between web and Unity platforms:
- 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 MPC.
Demo app
Explore the various MPC features and get a feel for how it can benefit your web app: xdemo.vercel.app.
Prerequisites
- Web
- Unity
- Complete the steps in Get started.
- Install the dependencies:
- Node.js v18.16 or later
- npm or Yarn for package installation
- Complete the steps in Get started.
- Install the dependencies:
- Unity v2020.3 or later
- Json.NET
- Dependencies in the library:
Steps
Step 1. Install the SDK
- Web
- Unity
Install the MPC JS SDK using npm:
npm install @axieinfinity/lockbox@2.1.0
Or using Yarn:
yarn add @axieinfinity/lockbox@2.1.0
Download the Unity package and import it into your project:
- Download the file
mpc.x.y.x.unitypackage
from the GitHub release page. - In the Unity editor, go to Assets > Import Package > Custom Package.
- Select the downloaded package, and then click Open.
Step 2. Initialize the SDK
- Web
- Unity
- Import the
Lockbox
package:
import { Lockbox } from "@axieinfinity/lockbox";
- 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:
Name | Type | Required | Description |
---|---|---|---|
chainId | Number | Required | Chain ID of the blockchain network to interact with: 2020 for the Ronin mainnet and 2021 for the Saigon testnet. The default is 2020 . |
overrideRpcUrl | String | Optional | RPC (remote procedure call) URL of the blockchain network. Must correspond to the specified chainId . |
accessToken | String | Optional | OAuth access token. |
serviceEnv | String | Optional | The server environment to connect to: prod for production and stag for staging. The default is stag . |
wasmParams | WasmParams | Optional | Configuration 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
});
///...
To get Lockbox ready, make sure to set the access token and client shard.
- Set the access token after authentication:
const accessToken = `${YOUR_ACCESS_TOKEN}`;
lockbox.setAccessToken(accessToken);
- Set the client shard after generating the key or decrypting:
const clientShard = `${YOUR_CLIENT_SHARD}`;
lockbox.setClientShard(clientShard);
To initialize the MPC SDK, call the Initialize
method first, before using any other SDK methods. This process automatically checks for and retrieves a backup of the client key shard, if available, from the Sky Mavis server.
MPC.Initialize(accessToken : string, env : Environment);
Parameters:
Name | Type | Description |
---|---|---|
AccessToken | String | Valid access token returned from an OAuth 2.0 provider. |
env | Environment | Defines the environment. Use Staging for the staging or testing environment. Use Production when the game is running in a live, production environment, serving real users. The default value is Staging . |
Example:
await MPC.Initialize(CreateAccessToken(userId), Environment.Staging);
await MPC.Initialize(CreateAccessToken(userId), Environment.Production);
If the user's access token changes during the game session, call the UpdateAccessToken
function to update it.
MPC.UpdateAccessToken(AccessToken);