Skip to main content

Initializing MPC Core Kit JS SDK for Web

After installation, the next step to use Web3Auth MPC Core Kit is to configure & initialize the SDK.

  1. Configure Web3AuthMPCCoreKit instance
  2. Initialize Web3AuthMPCCoreKit

Configure Instance

Please note that these are the most critical steps where you need to pass on different parameters according to the preference of your project.

Parameters

The Web3AuthMPCCoreKit constructor takes an object with Web3AuthOptions as input which helps you configure the SDK.

ParameterDescription
web3AuthClientIdThe Web3Auth Client ID for your application. Find one at https://dashboard.web3auth.io
manualSync?Enables you to manually sync with the Web3Auth Metadata Server, helping you manage the API calls to the server. We recommend using this approach. Default value is false.
baseUrl?URL of the service worker handling the authentication in popup flow. For general usecases, you don't need to change this value. Default value is ${window.location.origin}/serviceworker.
web3AuthNetwork?Web3Auth Network used for MPC Wallet Management. Use WEB3AUTH_NETWORK.DEVNET in testing environment and WEB3AUTH_NETWORK.Mainnet in production environment. Default value is WEB3AUTH_NETWORK.Mainnet.
sessionTime?Determine the session length in seconds. By default the value is set at 86400 seconds, ie. 1 day.
uxMode?Four uxModes are supported:
  • 'popup': In this uxMode, a popup will be shown to user for login.
  • 'redirect': In this uxMode, user will be redirected to a new window tab for login.
  • 'nodejs': Use this for Node.js projects.
  • 'react-native': Use this for React Native apps.
Use of 'redirect' mode is recommended in browsers where popups might get blocked.
enableLogging?Enables Logs for the SDK. Default value is false.
redirectPathName?Specifies the url path where user will be redirected after login. Redirect Uri for OAuth is baseUrl/redirectPathName.
disableHashedFactorKey?Disables the Hashed Key, making the sure user logs in always in a non-custodial mode. Recommended only if you have proper MFA flow setup for the user while creating the account. Default value is false.
tssLibThe threshold signing library to use:
  • For secp256k1 keyType, you can use the @toruslabs/tss-dkls-lib
  • For ed25519 keyType you can use @toruslabs/tss-frost-lib
hashedFactorNonce?Nonce for the hashed factor. Default value is web3AuthClientId. Learn more about hashed factor.
storageDefines the storage for MPC Core Kit's state.
useDKG?Specifies whether to use DKG or not. If set to false, the key would be securely generated on the client side, and imported to Web3Auth network. If set to true, the key would be generated using a distributed network.Setting the flag to false, and generating a key on the client side significantly improves the speed of first-time login. The default value secp256k1 is true. Please note, it is not supported for ed25519, and is always false.
useClientGeneratedTSSKey?Specifies whether to use client generated TSS key or not. The default value is set to false for secp256k1 and true for ed25519. The default value is set to true for ed25519 as it allows users to export the ed25519 key.
disableSessionManager?Specifies whether to disable the session manager or not. The default value is false. Please note, the session will still expire after the defined session time.

Usage

import { Web3AuthMPCCoreKit, WEB3AUTH_NETWORK } from "@web3auth/mpc-core-kit";
import { tssLib } from "@toruslabs/tss-dkls-lib";

const coreKitInstance = new Web3AuthMPCCoreKit({
web3AuthClientId: "YOUR_CLIENT_ID",
web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET,
manualSync: true, // This is the recommended approach
tssLib: tssLib,
storage: window.storage,
});

Initialize Web3AuthMPCCoreKit

To initialize the instance, you need to call the init method. The method also takes the InitParams as an input.

Parameters

ParameterDescription
handleRedirectResultHandles the redirect result during initialization. Default value is true.
rehydrateRehydrates the session during initialization. Default value is true.

Usage

// Web3AuthMPCCoreKit instance from previous steps
await coreKitInstance.init();