Core Concepts
Understanding the architecture of Wallet UI React Native Kit.
Wallet UI is designed to be a modular and extensible library for building wallet interactions in your app. Understanding its core architecture will help you use it more effectively and customize it to your needs.
Architecture Overview
@wallet-ui/react-native-kit
This is the main package for integrating Wallet UI into a React Native application using @solana/kit. It provides the necessary components and hooks to connect your dApp with a mobile wallet that supports the Mobile Wallet Adapter standard.
Key features include:
MobileWalletProvider: A context provider that sets up the wallet connection and RPC client, making them available throughout your component tree.useMobileWallethook: The primary hook for interacting with the wallet. It allows you to connect, disconnect, get account details, request signatures for transactions and messages, and obtain aTransactionSendingSigner.- Low-level hooks: For more advanced use cases, the package also exports hooks like
useAuthorizationfor fine-grained control over the wallet authorization process.
Key differences from Web3.js SDK
The Kit SDK uses @solana/kit instead of @solana/web3.js. This means:
Clientinstead ofConnection: The provider exposes aclientobject withrpcandrpcSubscriptionsinstead of aConnectionobject.SolanaClusterinstead of chain + endpoint: Configuration uses aclusterprop (aSolanaClusterobject withid,url, and optionalurlWs) instead of separatechainandendpointprops.Addressinstead ofPublicKey: Account addresses use theAddresstype from@solana/kitinstead ofPublicKeyfrom@solana/web3.js.Transactionfrom@solana/kit: Transactions use the KitTransactiontype instead ofTransaction/VersionedTransactionfrom@solana/web3.js.TransactionSendingSigner: TheuseMobileWallethook provides agetTransactionSignermethod that returns aTransactionSendingSignercompatible with@solana/kittransaction pipelines.
Custom RPC Client
The MobileWalletProvider creates a default RPC client using createSolanaRpc and createSolanaRpcSubscriptions from @solana/kit. You can customize this by passing a createClient function to the provider.
For advanced use cases, you can also use @solana/kit-plugins which provides a modular plugin system for assembling Solana clients with features like transaction planning, payer management, and more.
See the MobileWalletProvider documentation for examples.
Mobile Wallet Adapter
Mobile Wallet Adapter is an open protocol that allows mobile dApps to connect with mobile wallet applications. It defines a secure communication channel between the dApp and the wallet, enabling actions like:
- Authorizing a connection with one or more accounts.
- Requesting to sign and send transactions.
- Requesting to sign messages.
The @wallet-ui/react-native-kit package is an implementation of the client-side of this protocol, allowing your React Native application to act as a dApp and interact with any Mobile Wallet Adapter-compatible wallet installed on the user's device. This architecture decouples your dApp from any specific wallet implementation, giving users a choice of which wallet they want to use.