11---
2- title : " Initializing MPC Core Kit JS SDK for React Native"
2+ title : " Initializing MPC Core Kit React Native SDK "
33sidebar_label : " Initialize"
4- description : " Web3Auth MPC Core Kit JS SDK - Initialize for React Native | Documentation - Web3Auth"
4+ description : " Web3Auth MPC Core Kit React Native SDK - Initialize | Documentation - Web3Auth"
55---
66
77import ChainConfig from " @site/src/common/sdk/pnp/web/_chain-config.mdx" ;
@@ -48,36 +48,22 @@ export default function App() {
4848}
4949```
5050
51- ### Check for the Bridge State before Initing
52-
53- The new package of React Native exposes a ` resolveReady ` callback that notifies when the bridge is
54- ready to be used. Use this to init the SDK after the bridge has been configured.
55-
56- ``` js
57- useEffect (() => {
58- if (bridgeReady) {
59- const init = async () => {
60- try {
61- await coreKitInstance .init ();
62- } catch (error: any) {
63- uiConsole (error .message , " mounted caught" );
64- }
65- setCoreKitStatus (coreKitInstance .status );
66- };
67- init ();
68- }
69- }, [bridgeReady]);
70- ```
71-
7251## Configure Instance
7352
7453Please note that these are the most critical steps where you need to pass on different parameters
7554according to the preference of your project.
7655
7756### Parameters
7857
79- The Web3AuthMPCCoreKit constructor takes an object with ` Web3AuthOptions ` as input which helps you
80- configure the SDK.
58+ The ` mpclib.Web3AuthMPCCoreKitRN ` constructor takes an object with ` Web3AuthOptions ` as input which
59+ helps you configure the SDK.
60+
61+ :::note
62+
63+ Please, note we for the simplicity, we use the ` coreKitInstance ` to refer to the instance of
64+ ` mpclib.Web3AuthMPCCoreKitRN ` .
65+
66+ :::
8167
8268<Tabs
8369 defaultValue = " table"
@@ -271,13 +257,11 @@ export declare const UX_MODE: {
271257
272258``` javascript
273259import {
274- makeEthereumSigner ,
275260 mpclib ,
276261 TssDklsLib ,
277262 WEB3AUTH_NETWORK ,
278263 Web3AuthOptions ,
279264} from " @web3auth/react-native-mpc-core-kit" ;
280- import { EthereumSigningProvider } from " @web3auth/ethereum-mpc-provider" ;
281265import EncryptedStorage from " react-native-encrypted-storage" ; // Used to store the session & device factor keys
282266
283267// setup async storage for react native
@@ -301,21 +285,6 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
301285 storage: asyncStorageKey, // Add the storage property
302286} as Web3AuthOptions);
303287// focus-end
304-
305- const chainConfig = {
306- chainNamespace: CHAIN_NAMESPACES .EIP155 ,
307- chainId: " 0xaa36a7" , // Please use 0x1 for Mainnet
308- rpcTarget: " https://rpc.ankr.com/eth_sepolia" ,
309- displayName: " Ethereum Sepolia Testnet" ,
310- blockExplorerUrl: " https://sepolia.etherscan.io/" ,
311- blockExplorer: " https://sepolia.etherscan.io/" ,
312- ticker: " ETH" ,
313- tickerName: " Ethereum" ,
314- };
315-
316- // Setup provider for EVM Chain
317- const evmProvider = new EthereumSigningProvider ({ config: { chainConfig } });
318- evmProvider .setupProvider (makeEthereumSigner (coreKitInstance));
319288```
320289
321290</TabItem >
@@ -372,13 +341,11 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
372341
373342``` javascript
374343import {
375- makeEthereumSigner ,
376344 mpclib ,
377345 TssDklsLib ,
378346 WEB3AUTH_NETWORK ,
379347 Web3AuthOptions ,
380348} from " @web3auth/react-native-mpc-core-kit" ;
381- import { EthereumSigningProvider } from " @web3auth/ethereum-mpc-provider" ;
382349import * as SecureStore from " expo-secure-store" ; // Used to store the session & device factor keys
383350
384351// setup async storage for react native
@@ -402,21 +369,6 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
402369 storage: asyncStorageKey, // Add the storage property
403370} as Web3AuthOptions);
404371// focus-end
405-
406- const chainConfig = {
407- chainNamespace: CHAIN_NAMESPACES .EIP155 ,
408- chainId: " 0xaa36a7" , // Please use 0x1 for Mainnet
409- rpcTarget: " https://rpc.ankr.com/eth_sepolia" ,
410- displayName: " Ethereum Sepolia Testnet" ,
411- blockExplorerUrl: " https://sepolia.etherscan.io/" ,
412- blockExplorer: " https://sepolia.etherscan.io/" ,
413- ticker: " ETH" ,
414- tickerName: " Ethereum" ,
415- };
416-
417- // Setup provider for EVM Chain
418- const evmProvider = new EthereumSigningProvider ({ config: { chainConfig } });
419- evmProvider .setupProvider (makeEthereumSigner (coreKitInstance));
420372```
421373
422374</TabItem >
@@ -461,6 +413,35 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
461413
462414</Tabs >
463415
416+ ## Additional Configuration for EVM Chains
417+
418+ If you are using the SDK with EVM compatible chains, you can use the ` EthereumSigningProvider ` to
419+ setup the provider for the EVM chain. This provider is EIP1193 compatible and can be used with
420+ ` web3.js ` , ` ethers.js ` , or ` viem ` to make integration with EVM compatible chains easier.
421+
422+ You need to pass in the ` chainConfig ` object to the provider. The ` chainConfig ` object contains the
423+ basic details of the chain you are using.
424+
425+ ``` js
426+ import { makeEthereumSigner } from " @web3auth/react-native-mpc-core-kit" ;
427+ import { EthereumSigningProvider } from " @web3auth/ethereum-mpc-provider" ;
428+
429+ const chainConfig = {
430+ chainNamespace: CHAIN_NAMESPACES .EIP155 ,
431+ chainId: " 0xaa36a7" , // Please use 0x1 for Mainnet
432+ rpcTarget: " https://rpc.ankr.com/eth_sepolia" ,
433+ displayName: " Ethereum Sepolia Testnet" ,
434+ blockExplorerUrl: " https://sepolia.etherscan.io/" ,
435+ blockExplorer: " https://sepolia.etherscan.io/" ,
436+ ticker: " ETH" ,
437+ tickerName: " Ethereum" ,
438+ };
439+
440+ // Setup provider for EVM Chain
441+ const evmProvider = new EthereumSigningProvider ({ config: { chainConfig } });
442+ evmProvider .setupProvider (makeEthereumSigner (coreKitInstance));
443+ ```
444+
464445## Initialize Web3AuthMPCCoreKit
465446
466447To initialize the instance, you need to call the ` init ` method. The method also takes the
@@ -512,3 +493,24 @@ export interface InitParams {
512493// Web3AuthMPCCoreKit instance from previous steps
513494await coreKitInstance .init ();
514495```
496+
497+ ### Check for the Bridge State before Initing
498+
499+ The ` Bridge ` exposes a ` resolveReady ` callback that notifies when the SDK's bridge is ready to be
500+ used. Use this to init the SDK after the bridge has been configured.
501+
502+ ``` js
503+ useEffect (() => {
504+ if (bridgeReady) {
505+ const init = async () => {
506+ try {
507+ await coreKitInstance .init ();
508+ } catch (error: any) {
509+ uiConsole (error .message , " mounted caught" );
510+ }
511+ setCoreKitStatus (coreKitInstance .status );
512+ };
513+ init ();
514+ }
515+ }, [bridgeReady]);
516+ ```
0 commit comments