Notice: This library assumes you have already enabled prerequisite support for Web3 inside your application. This can be done by creating a new project using npx create-react-native-dapp, or by introducing support for Web3 in an existing project by using npx rn-nodeify --install --hack.
This library is implemented using the React Context API, which is used to help make an instance of a connector accessible globally throughout your application. This permits you to use a uniform instance within even deeply nested components, and ensures your rendered application is always synchronized against the connector state.
WalletConnectProvider
At the root of your application, you can declare a WalletConnectProvider which controls access and persistence to a connector instance:
Above, we pass the WalletConnectProvider two required parameters; redirectUrl and storageOptions:
The redirectUrl is used to help control navigation between external wallets and your application. On the web, you only need to specify a valid application route; whereas on mobile platforms, you must specify a deep link URI scheme.
The storageOptions prop allows you to specify the storage engine which must be used to persist session data.
In the snippet above, aside from the required props, we can see the default configuration of the WalletConnectProvider.
Tip: Your custom options are merged deeply against this default configuration. Therefore it's possible to override individual nested properties without being required to define all of them.
This is almost identical in functionality to the manual implementation of a WalletConnectProvider, with the key difference that we're able to make a call to useWalletConnect directly from the App component. By contrast, in the previous example only child components of the WalletConnectProvider may be able to invoke this hook.
useWalletConnect
The useWalletConnect hook provides access to a WalletConnectconnector instance which is accessible on Android, iOS and the Web. This conforms to the original specification:
@walletconnect/react-native-dapp also permits you to customize the presentation of the QrcodeModal. This is achieved by passing the Render Callback prop, renderQrcodeModal, to our calls to withWalletConnect or instances of WalletConnectProvider.
For example, you could choose to render a wallet selection using a BottomSheet opposed to a Modal: