|
| 1 | +--- |
| 2 | +title: PnP React Native - v7 to v8 |
| 3 | +description: "PnP React Native SDK - v7 to v8 | Documentation - Web3Auth" |
| 4 | +--- |
| 5 | + |
| 6 | +import TabItem from "@theme/TabItem"; |
| 7 | +import Tabs from "@theme/Tabs"; |
| 8 | + |
| 9 | +This migration guide provides steps for upgrading from version v7 to v8 of the Web3Auth React Native |
| 10 | +SDK. |
| 11 | + |
| 12 | +## Package Updates |
| 13 | + |
| 14 | +Update your dependencies in `package.json`: |
| 15 | + |
| 16 | +```typescript |
| 17 | +// remove-next-line |
| 18 | +"@web3auth/react-native-sdk": "^7.x.x" |
| 19 | +// add-next-line |
| 20 | +"@web3auth/react-native-sdk": "^8.0.0" |
| 21 | + |
| 22 | +// remove-next-line |
| 23 | +"@web3auth/ethereum-provider": "^8.x.x" |
| 24 | +// add-next-line |
| 25 | +"@web3auth/ethereum-provider": "^9.3.0" |
| 26 | + |
| 27 | +// add-next-line |
| 28 | +"react-native-quick-crypto": "^0.7.6" |
| 29 | +``` |
| 30 | + |
| 31 | +## Breaking Changes |
| 32 | + |
| 33 | +### Network Enum Update |
| 34 | + |
| 35 | +The `OPENLOGIN_NETWORK` enum has been replaced with `WEB3AUTH_NETWORK`: |
| 36 | + |
| 37 | +```typescript |
| 38 | +// remove-next-line |
| 39 | +import { LOGIN_PROVIDER, OPENLOGIN_NETWORK } from "@web3auth/react-native-sdk"; |
| 40 | +// add-next-line |
| 41 | +import { LOGIN_PROVIDER, WEB3AUTH_NETWORK } from "@web3auth/react-native-sdk"; |
| 42 | + |
| 43 | +// remove-next-line |
| 44 | +network: OPENLOGIN_NETWORK.SAPPHIRE_MAINNET, |
| 45 | +// add-next-line |
| 46 | +network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
| 47 | +``` |
| 48 | + |
| 49 | +### Mandatory privateKeyProvider in Constructor |
| 50 | + |
| 51 | +The `privateKeyProvider` parameter must now be provided in the Web3Auth constructor: |
| 52 | + |
| 53 | +<Tabs> |
| 54 | +<TabItem value="bare" label="Bare React Native" default> |
| 55 | + |
| 56 | +```typescript |
| 57 | +const web3auth = new Web3Auth(WebBrowser, EncryptedStorage, { |
| 58 | + clientId: "YOUR_CLIENT_ID", |
| 59 | + network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
| 60 | + redirectUrl: redirectUrl, |
| 61 | + // add-next-line |
| 62 | + privateKeyProvider: ethereumPrivateKeyProvider, |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +</TabItem> |
| 67 | +<TabItem value="expo" label="Expo"> |
| 68 | + |
| 69 | +```typescript |
| 70 | +const web3auth = new Web3Auth(WebBrowser, SecureStore, { |
| 71 | + clientId: "YOUR_CLIENT_ID", |
| 72 | + network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
| 73 | + redirectUrl: redirectUrl, |
| 74 | + // add-next-line |
| 75 | + privateKeyProvider: ethereumPrivateKeyProvider, |
| 76 | +}); |
| 77 | +``` |
| 78 | + |
| 79 | +</TabItem> |
| 80 | +</Tabs> |
| 81 | + |
| 82 | +### Connection Status Changes |
| 83 | + |
| 84 | +The `privKey` property has been removed. Use the `connected` property instead. Additionally, since |
| 85 | +the private key provider is taken as a parameter in the constructor, the `setupProvider` method is |
| 86 | +no longer needed, you can directly use the `provider` property from the Web3Auth instance. |
| 87 | + |
| 88 | +```typescript |
| 89 | +// remove-start |
| 90 | +if (web3auth.privKey) { |
| 91 | + await ethereumPrivateKeyProvider.setupProvider(web3auth.privKey); |
| 92 | + setProvider(ethereumPrivateKeyProvider); |
| 93 | +// remove-end |
| 94 | +// add-next-line |
| 95 | +if (web3auth.connected) { |
| 96 | + // add-next-line |
| 97 | + setProvider(web3auth.provider); |
| 98 | + setLoggedIn(true); |
| 99 | +} |
| 100 | +``` |
| 101 | +
|
| 102 | +### Authentication URL Change |
| 103 | +
|
| 104 | +Update the redirect URL pattern: |
| 105 | +
|
| 106 | +```typescript |
| 107 | +// remove-next-line |
| 108 | +const redirectUrl = `${scheme}://openlogin`; |
| 109 | +// add-next-line |
| 110 | +const redirectUrl = `${scheme}://auth`; |
| 111 | +``` |
| 112 | +
|
| 113 | +### globals.js Updates |
| 114 | +
|
| 115 | +Update your globals.js file with react-native-quick-crypto. This is required for polyfilling the |
| 116 | +`crypto` module. |
| 117 | +
|
| 118 | +```typescript |
| 119 | +global.Buffer = require("buffer").Buffer; |
| 120 | + |
| 121 | +// add-start |
| 122 | +// eslint-disable-next-line import/first |
| 123 | +import { install } from "react-native-quick-crypto"; |
| 124 | + |
| 125 | +install(); |
| 126 | +// add-end |
| 127 | + |
| 128 | +// Needed so that 'stream-http' chooses the right default protocol. |
| 129 | +global.location = { |
| 130 | + protocol: "file:", |
| 131 | +}; |
| 132 | + |
| 133 | +global.process.version = "v16.0.0"; |
| 134 | +if (!global.process.version) { |
| 135 | + global.process = require("process"); |
| 136 | + console.log({ process: global.process }); |
| 137 | +} |
| 138 | + |
| 139 | +process.browser = true; |
| 140 | +``` |
| 141 | +
|
| 142 | +Make sure to import required files in your entry point: |
| 143 | +
|
| 144 | +```typescript |
| 145 | +import "./globals"; |
| 146 | +import "@ethersproject/shims"; |
| 147 | +import "@expo/metro-runtime"; |
| 148 | +``` |
| 149 | +
|
| 150 | +## Need Help? |
| 151 | +
|
| 152 | +If you encounter any issues during migration, please: |
| 153 | +
|
| 154 | +- Refer to our [official documentation](https://web3auth.io/docs/sdk/react-native/) |
| 155 | +- Open a new thread in our |
| 156 | + [community forum with the react-native tag](https://web3auth.io/community/tag/react-native) |
0 commit comments