11---
2- title : " Initializing MPC Core Kit Web SDK"
2+ title : " Initializing MPC Core Kit JS SDK"
33sidebar_label : " Initialize"
44displayed_sidebar : sdk
5- description : " Web3Auth MPC Core Kit Web SDK - Initialize | Documentation - Web3Auth"
5+ description : " Web3Auth MPC Core Kit JS SDK - Initialize | Documentation - Web3Auth"
66---
77
88import ChainConfig from " @site/src/common/sdk/pnp/web/_chain-config.mdx" ;
@@ -15,6 +15,7 @@ After Installation, the next step to use Web3Auth MPC Core Kit is to Initialize
1515However, the Initialization is a two step process, ie.
1616
1717- [ Instantiation of ` Web3AuthMPCCoreKit ` ] ( #instantiating-web3auth )
18+ - [ Instantiation of the Signing Provider package] ( #instantiating-provider )
1819- [ Initialization of ` Web3AuthMPCCoreKit ` ] ( #initializing-web3auth )
1920
2021## Instantiating Web3Auth
@@ -25,6 +26,38 @@ However, the Initialization is a two step process, ie.
2526import { Web3AuthMPCCoreKit , WEB3AUTH_NETWORK } from " @web3auth/mpc-core-kit" ;
2627```
2728
29+ :::info Additional imports needed for React Native
30+
31+ In order to make this SDK compatible with the React Native development environment, you need to
32+ additionally import the following packages:
33+
34+ ``` tsx
35+ import EncryptedStorage from " react-native-encrypted-storage" ; // Used to store the session & device factor keys
36+ import * as TssLibRN from " @toruslabs/react-native-tss-lib-bridge" ; // The TSS library for React Native
37+ import { Bridge } from " @toruslabs/react-native-tss-lib-bridge" ; // A bridge to be imported to the React Native environment
38+ ```
39+
40+ While initializing the SDK, you need to pass the ` EncryptedStorage ` and ` TssLibRN ` as arguments to
41+ the ` Web3AuthOptions ` object. The ` Bridge ` is used to bridge the TSS library to the React Native
42+ environment, it has to be imported in the React Native environment, at the end of the page.
43+
44+ ``` tsx title="App.tsx"
45+ import { Bridge } from " @toruslabs/react-native-tss-lib-bridge" ;
46+
47+ export default function App() {
48+ // Misc App related functions
49+ return (
50+ <View >
51+ { /* <YOUR APP GOES HERE> */ }
52+ // highlight-next-line
53+ <Bridge /> // <- Add this line
54+ </View >
55+ );
56+ }
57+ ```
58+
59+ :::
60+
2861#### Assign the ` Web3AuthMPCCoreKit ` class to a variable
2962
3063``` javascript
@@ -202,18 +235,6 @@ export declare const UX_MODE: {
202235
203236</Tabs >
204237
205- #### Adding a Custom Chain Configuration
206-
207- :::warning
208-
209- Currently Web3Auth MPC Core Kit supports ** only EVM Compatible Chains** . We're constantly working on adding support for more chains.
210-
211- :::
212-
213- #### ` chainConfig `
214-
215- <ChainConfig />
216-
217238##### Usage
218239
219240``` javascript
@@ -232,14 +253,98 @@ chainConfig: {
232253
233254### Example
234255
256+ #### Web
257+
235258``` javascript
259+ import { Web3AuthMPCCoreKit , WEB3AUTH_NETWORK } from " @web3auth/mpc-core-kit" ;
260+
236261const coreKitInstance = new Web3AuthMPCCoreKit ({
237- web3AuthClientId: " BILuyqFCuDXAqVmAuMbD3c4oWEFd7PUENVPyVC-zmsF9euHAvUjqbTCpKw6gO05DBif1YImIVtyaxmEbcLLlb6w" ,
262+ web3AuthClientId:
263+ " BILuyqFCuDXAqVmAuMbD3c4oWEFd7PUENVPyVC-zmsF9euHAvUjqbTCpKw6gO05DBif1YImIVtyaxmEbcLLlb6w" ,
238264 web3AuthNetwork: WEB3AUTH_NETWORK .MAINNET ,
239265 uxMode: " popup" ,
266+ manualSync: true , // This is the recommended approach
267+ });
268+ ```
269+
270+ #### React Native
271+
272+ ``` ts
273+ import { Web3AuthMPCCoreKit , WEB3AUTH_NETWORK } from " @web3auth/mpc-core-kit" ;
274+ import EncryptedStorage from " react-native-encrypted-storage" ; // Used to store the session & device factor keys
275+ import * as TssLibRN from " @toruslabs/react-native-tss-lib-bridge" ; // The TSS library for React Native
276+
277+ const coreKitInstance = new Web3AuthMPCCoreKit ({
278+ web3AuthClientId:
279+ " BILuyqFCuDXAqVmAuMbD3c4oWEFd7PUENVPyVC-zmsF9euHAvUjqbTCpKw6gO05DBif1YImIVtyaxmEbcLLlb6w" ,
280+ web3AuthNetwork: WEB3AUTH_NETWORK .MAINNET ,
281+ chainConfig ,
282+ setupProviderOnInit: false ,
283+ uxMode: " react-native" ,
284+ asyncStorageKey: {
285+ getItem : async (key : string ) => {
286+ return EncryptedStorage .getItem (key );
287+ },
288+ setItem : async (key : string , value : string ) => {
289+ return EncryptedStorage .setItem (key , value );
290+ },
291+ },
292+ tssLib: TssLibRN ,
293+ manualSync: true , // This is the recommended approach
240294});
241295```
242296
297+ ## Instantiating Provider
298+
299+ As a next step, you need to set up the particular signing provider from Web3Auth and pass the
300+ ` coreKitInstance ` into it. This provider is used to make calls to the selected blockchain.
301+ Currently, Web3Auth exposes the following signing provider packages to be integrated within the SDK:
302+
303+ - [ EthereumSigningProvider] ( /sdk/providers/evm-mpc )
304+
305+ #### Adding a Custom Chain Configuration
306+
307+ :::warning
308+
309+ Currently Web3Auth MPC Core Kit supports ** only EVM Compatible Chains** . We're constantly working on
310+ adding support for more chains.
311+
312+ :::
313+
314+ #### ` chainConfig `
315+
316+ <ChainConfig />
317+
318+ <Tabs
319+ defaultValue = " eth"
320+ values = { [
321+ { label: " ETH" , value: " eth" },
322+ ]}
323+ >
324+
325+ <TabItem value = " eth" >
326+
327+ ``` javascript title="Usage"
328+ import { EthereumSigningProvider } from " @web3auth/ethereum-mpc-provider" ;
329+ import { CHAIN_NAMESPACES } from " @web3auth/base" ;
330+
331+ const chainConfig = {
332+ chainNamespace: CHAIN_NAMESPACES .EIP155 ,
333+ chainId: " 0xaa36a7" , // Please use 0x1 for Mainnet
334+ rpcTarget: " https://rpc.ankr.com/eth_sepolia" ,
335+ displayName: " Ethereum Sepolia Testnet" ,
336+ blockExplorerUrl: " https://sepolia.etherscan.io/" ,
337+ ticker: " ETH" ,
338+ tickerName: " Ethereum" ,
339+ };
340+
341+ const evmProvider = new EthereumSigningProvider ({ config: { chainConfig } });
342+ evmProvider .setupProvider (coreKitInstance);
343+ ```
344+
345+ </TabItem >
346+ </Tabs >
347+
243348## Initializing Web3Auth
244349
245350#### ` init(params?: InitParams) `
@@ -282,7 +387,8 @@ export interface InitParams {
282387
283388</Tabs >
284389
285- The final step in the initialization process is to initialize the ` Web3AuthMPCCoreKit ` instance, ie. ` coreKitInstance ` in our case.
390+ The final step in the initialization process is to initialize the ` Web3AuthMPCCoreKit ` instance, ie.
391+ ` coreKitInstance ` in our case.
286392
287393This is done by calling the ` init() ` function of ` coreKitInstance ` .
288394
0 commit comments