Skip to main content

Initializing PnP React Native SDK

After Installation, the next step to use Web3Auth is to Initialize the SDK. The Initialization is a two-step process,

Please note that these are the most critical steps where you need to pass on different parameters according to the preference of your project. Additionally, Whitelabeling and Custom Authentication have to be configured within this step, if you wish to customize your Web3Auth Instance.

Importing Required packages

Importing Web3Auth

You may also import additional types from the SDK to help in the development process.

import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK } from "@web3auth/react-native-sdk";

Importing a WebBrowser implementation

import * as WebBrowser from "expo-web-browser";

Importing a Storage implementation

import * as SecureStore from "expo-secure-store";

Instantiating Web3Auth

NOTE

Now with react-native-sdk v4 SecureStore or EncryptedStorage gets passed with the Web3Auth constructor, depending on the workflow you are using. This is due to the addition of session management without storing the private key in the device.

const web3auth = new Web3Auth(WebBrowser, SecureStore, SdkInitParams);

SdkInitParams object

The Web3Auth constructor in the React Native SDK takes an SdkInitParams object respectively as an argument. The fields of such objects are listed below.

ParameterDescription
clientIdYour Web3Auth Client ID. You can get it from Web3Auth Dashboard under project details. It's a mandatory field of type string
networkDefines the Web3Auth network. It's a mandatory field of type OPENLOGIN_NETWORK_TYPE.
redirectUrlURL that Web3Auth will redirect API responses upon successful authentication from browser. It's a mandatory field of type string.
whiteLabel?WhiteLabel options for web3auth. It helps you define custom UI, branding, and translations for your brand app. It takes WhiteLabelData as a value.
loginConfig?Login config for the custom verifiers. It takes LoginConfig as a value.
useCoreKitKey?Use CoreKit Key to get core kit key. It's an optional field with default value as false.
mfaSettings?Allows developers to configure the Mfa settings for authentication. It takes MfaSettings as a value.
sessionTime?It allows developers to configure the session management time. Session Time is in seconds, default is 86400 seconds which is 1 day. sessionTime can be max 7 days
storageServerUrlSpecify a custom storage url. Default value is https://broadcast-server.tor.us.
storageKeySpecify the storage key. Setting to "local" will persist social login session accross browser tabs. Available options are "local" and "session".
useMpcWhether to use openlogin MPC or not. Default value is false.

Example

import * as WebBrowser from "expo-web-browser";
import * as SecureStore from "expo-secure-store";
import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK } from "@web3auth/react-native-sdk";

const resolvedRedirectUrl =
Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
? Linking.createURL("web3auth", {})
: Linking.createURL("web3auth", { scheme: scheme });

const clientId = "YOUR WEB3AUTH CLIENT ID";

const web3auth = new Web3Auth(WebBrowser, SecureStore, {
clientId,
network: OPENLOGIN_NETWORK.SAPPHIRE_MAINNET, // or other networks
});