Skip to main content

Create a wallet

Overview

This guide describes how to create a blockchain wallet using the MPC (Multi-Party Computation) SDK.

This process involves generating a client-side private key shard, encrypting it with a passphrase, and backing up the encrypted shard. The user's wallet address is then retrieved for use in transactions.

Prerequisites

Complete the steps in Get started.

Steps

Step 1. Get the user's access token

Get the user's access token after authenticating the user with Mavis Account or Mavis ID.

Step 2. Collect a passphrase

A passphrase is a crucial part of the wallet creation process. It's used to encrypt the user's private key shard. The passphrase is used to decrypt the private key shard during wallet recovery.

The passphrase must meet the following requirements:

  • Contain at least 8 characters
  • Include at least one number
  • Include at least one special character

Step 3. Create a wallet

  1. Create a client-side private key shard:

Function signature:

async lockbox.genMpc() : KeygenResult ;

Result:

{
key: string;
meta: {
requestId: string;
uuid: string;
}
}

Example:

const result = await lockbox.genMpc();
console.log("Client's key shard : ", result.key);
//...
  1. Encrypt the client key shard with the passphrase:

Function signature:

encryptClientShard = async (passphrase: string, recoveryPhraseLength?: number)

Parameters:

NameTypeRequiredDescription
passphraseStringRequiredThe user's passphrase for encrypting the client shard.
recoveryPhraseLengthNumberOptionalThe number of words in the recovery kit used to decrypt the client shard. Default is 8 words.

Result:

NameTypeDescription
encryptedKeyStringThe client shard encrypted with the passphrase.
recoveryPhraseStringA set of words used to decrypt the encrypted client shard if the user loses their passphrase.
caution

The user must remember their passphrase and recovery kit. If the user loses the passphrase and recovery kit, they lose access to their wallet, and neither Sky Mavis nor you as a developer can recover it.

Example:

const passphrase: string = `${YOUR_PASSPHRASE}`;
const recoveryPhraseLength: number = 8; // Default

// Return encrypted client shard
const result = await lockbox.encryptClientShard(
passphrase,
recoveryPhraseLength
);
//..
  1. Back up the client shard:

Function signature:

backupClientShard = async (encryptedClientShard: string)

Parameters:

NameTypeRequiredDescription
encryptedClientShardStringRequiredThe encrypted client shard.

Result:

NameTypeDescription
encryptedKeyStringThe client shard encrypted with the passphrase.

Example:

const result = await lockbox.backupClientShard(encryptedClientShard);
console.log("Encrypted client shard: ", result);
//..
info

Sky Mavis supports only MPC_CMP_ECDSA_SECP256K1, compatible with most EVM (Ethereum Virtual Machine) chains.

Here's a complete example:

// Initialize lockbox

// Create a handler to create a wallet
const handleCreateWallet = async () => {
try {
// Setup password
const passphrase = `${PASSPHRASE}`;
// Generate MPC key for new wallet
const response = await lockbox.genMpc();
// Set client shard
lockbox.setClientShard(response.key);
// Encrypt client shard
const encryptedResult = await lockbox.encryptClientShard(passphrase, 8);
// Back up key to server
await lockbox.backupClientShard(encryptedResult.encryptedKey);
} catch (error) {
console.error(error);
}
};

Step 4. Retrieve wallet address

Retrieve the wallet's public key to use for transactions.

Function signature:

async function getUserProfile()

Result:

NameTypeDescription
addressStringMPC address.
updatedAtNumberLatest updated profile time.
uuidStringUser ID .

Example:

const result = await lockbox.getUserProfile();
console.log("Address : ", result.address);

Step 5. Verify wallet creation

Form a request to the Mavis Account service to verify the wallet creation.

Request:

GET https://api-gateway.skymavis.com/account/userinfo
X-API-Key: {YOUR_API_KEY} // API key from the Developer Console
Authorization: Bearer {ACCESS_TOKEN} // User's access token

Response:

{
"ronin_address": "<string>",
"wallet_type": "mpc"
}

The ronin_address field must match the wallet public key. The wallet_type field must be equal to mpc.

Next steps

Send a transaction