diff --git a/appkit/react-native/core/components.mdx b/appkit/react-native/core/components.mdx index 4031a0aaf..cf4d9f0cb 100644 --- a/appkit/react-native/core/components.mdx +++ b/appkit/react-native/core/components.mdx @@ -2,25 +2,27 @@ title: Components --- -# Components +AppKit comes with a set of pre-built UI components to help you quickly integrate wallet connection and display functionalities into your React Native application. You can import them directly from `@reown/appkit-react-native`. -AppKit comes with a set of components in case you want to integrate fast. -You can import them from `@reown/appkit-wagmi-react-native` or `@reown/appkit-ethers-react-native` - -### List of components available in AppKit package ### `` +The `AppKitButton` is a versatile component that intelligently adapts its appearance and behavior based on the current connection status. +- When no wallet is connected, it functions as a "Connect Wallet" button. +- When a wallet is connected, it functions as an "Account" button, typically displaying account information and a disconnect option. + | Variable | Description | Type | | -------------- | ---------------------------------------------------- | ------------------ | | `disabled` | Enable or disable the button. | `boolean` | | `balance` | Show or hide the user's balance. | `'show' \| 'hide'` | | `size` | Default size for the button. | `'md' \| 'sm'` | -| `label` | The text shown in the button. | `string` | +| `label` | The text shown in the button (primarily when disconnected). | `string` | | `loadingLabel` | The text shown in the button when the modal is open. | `string` | ### `` +This button is specifically designed to display when a user is connected. It typically shows account information and provides a way to disconnect or manage the connected account. + | Variable | Description | Type | | ---------- | -------------------------------- | ------------------ | | `disabled` | Enable or disable the button. | `boolean` | @@ -28,6 +30,8 @@ You can import them from `@reown/appkit-wagmi-react-native` or `@reown/appkit-et ### `` +This button is primarily used to initiate the connection process when no user is connected. + | Variable | Description | Type | | -------------- | ---------------------------------------------------- | -------------- | | `size` | Default size for the button. | `'md' \| 'sm'` | @@ -36,6 +40,8 @@ You can import them from `@reown/appkit-wagmi-react-native` or `@reown/appkit-et ### `` +This button displays the currently active network of the connection. When pressed, it opens the network selection view within the AppKit modal, allowing users to switch networks. + | Variable | Description | Type | | ---------- | ----------------------------- | --------- | | `disabled` | Enable or disable the button. | `boolean` | diff --git a/appkit/react-native/core/email.mdx b/appkit/react-native/core/email.mdx index 962bfe38a..a2f18f50d 100644 --- a/appkit/react-native/core/email.mdx +++ b/appkit/react-native/core/email.mdx @@ -2,8 +2,9 @@ title: Email & Socials --- -import WagmiImplementation from "/snippets/appkit/react-native/wagmi/email.mdx"; -import EthersImplementation from "/snippets/appkit/react-native/ethers/email.mdx"; + + Feature not available yet + AppKit enables passwordless Web3 onboarding and authentication, allowing your users interact with your application by creating a non-custodial wallet with just their emails or social network. @@ -15,27 +16,12 @@ Due to Safari’s strict third-party cookie policies, the SDK is not preserving ## Integration - +### Update your Cloud settings +1. Go to your [Cloud](https://cloud.reown.com) project +2. Open Dashboard and scroll down to Mobile Application IDs menu +3. Add your iOS Bundle ID and/or your Android Package Name +* Changes might take some minutes to impact - - ### Update your Cloud settings - 1. Go to your [Cloud](https://cloud.reown.com) project - 2. Open Dashboard and scroll down to Mobile Application IDs menu - 3. Add your iOS Bundle ID and/or your Android Package Name - * Changes might take some minutes to impact - - - - - - ### Update your Cloud settings 1. Go to your [Cloud](https://cloud.reown.com) - project 2. Open Dashboard and scroll down to Mobile Application IDs menu 3. - Add your iOS Bundle ID and/or your Android Package Name * Changes might take - some minutes to impact - - - - ## Options diff --git a/appkit/react-native/core/hooks.mdx b/appkit/react-native/core/hooks.mdx index 709edc934..31e81d882 100644 --- a/appkit/react-native/core/hooks.mdx +++ b/appkit/react-native/core/hooks.mdx @@ -2,262 +2,194 @@ title: Hooks --- -import WagmiHooks from "/snippets/appkit/react-native/wagmi/hooks.mdx"; -import EthersHooks from "/snippets/appkit/react-native/ethers/hooks.mdx"; -import Ethers5Hooks from "/snippets/appkit/react-native/ethers5/hooks.mdx"; +AppKit for React Native provides a set of hooks to interact with the wallet connection lifecycle, access connection state, and control the modal. -## useAppKit +All hooks are imported from `@reown/appkit-react-native`. -Control the modal with the `useAppKit` hook +## `useAppKit()` - +This is the primary hook to get AppKit state and control the modal. - -```ts -import { useAppKit } from '@reown/appkit-wagmi-react-native' +```typescript +import { useAppKit } from '@reown/appkit-react-native'; -export default function Component() { - const { open, close } = useAppKit() +export default function MyComponent() { + const { + // Modal Control + open, // Function to open the modal, optionally with a specific view (e.g., open({ view: 'Networks' })) + close, // Function to close the modal + isOpen, // Boolean indicating if the modal is currently open -open() - -//... + // Actions + disconnect, // Function to disconnect the current session + switchNetwork, // Function to attempt to switch to a different chain/network (e.g., switchNetwork(network: AppKitNetwork)) + } = useAppKit(); } - -```` - - - -```ts -import { useAppKit } from '@reown/appkit-ethers-react-native' - -export default function Component() { - const { open, close } = useAppKit() - - open() - - //... -} -```` - - - - -```ts -import { useAppKit } from '@reown/appkit-ethers5-react-native' - -export default function Component() { - const { open, close } = useAppKit() - -open() - -//... -} - -```` - - - - -You can also select the modal's view when calling the `open` function - -```ts -open({ view: 'Account' }) - -// to connect and show multi wallets view -open({ view: 'Connect'}) - -// to connect and show only solana wallets -open({ view: 'Connect', namespace: 'solana' }) - -// to connect and show only bitcoin wallets -open({ view: 'Connect', namespace: 'bip122' }) - -// to connect and show only ethereum wallets -open({ view: 'Connect', namespace: 'eip155' }) -```` - -List of views you can select - -| Variable | Description | -| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `Connect` | Principal view of the modal - default view when disconnected. A `namespace` can be selected to connect to a specific network (solana, bip122 or eip155). | -| `Account` | User profile - default view when connected. | -| `Networks` | List of available networks - you can select and target a specific network before connecting. | -| `WhatIsANetwork` | "What is a network" onboarding view. | -| `WhatIsAWallet` | "What is a wallet" onboarding view. | - -## useAppKitState - -Get the current value of the modal's state - - - - -```ts -import { useAppKitState } from '@reown/appkit-wagmi-react-native' - -const { open, selectedNetworkId } = useAppKitState() - -```` - - - -```ts -import { useAppKitState } from '@reown/appkit-ethers-react-native' - -const { open, selectedNetworkId } = useAppKitState() -``` - - - - -```ts -import { useAppKitState } from '@reown/appkit-ethers5-react-native' - -const { open, selectedNetworkId } = useAppKitState() ``` - - - - -The modal state consists of two reactive values: - -| State | Description | Type | -|--------------------|-----------------------------------------------------------------------------|-----------| -| `open` | Open state will be true when the modal is open and false when closed. | `boolean` | -| `selectedNetworkId`| The current chain id selected by the user. | `number` | - -## useAppKitEvents -Get the last tracked modal event. The hook accepts an optional callback function that is executed when the event is triggered. +Opening the Modal with a Specific View - +You can direct the modal to open to a specific view using the `open` function: - -```ts -import { useAppKitEvents } from '@reown/appkit-wagmi-react-native' - -const event = useAppKitEvents(event => { - // your code here -}) +```typescript +open({ view: 'Account' }); // Opens to the account view if connected +open({ view: 'Connect' }); // Opens to the wallet selection view +open({ view: 'Networks' }); // Opens to the network selection view ``` - - - -```ts -import { useAppKitEvents } from '@reown/appkit-ethers-react-native' - -const event = useAppKitEvents(event => { - // your code here -}) +Here is a list of possible views you can select: + +| Variable | Description | +| ---------------- | ------------------------------------------------------------------------------------------------ | +| `Connect` | Principal view of the modal - default view when disconnected. | +| `Account` | User profile - default view when connected. | +| `Networks` | List of available networks - you can select and target a specific network before connecting. | +| `WhatIsANetwork` | "What is a network" onboarding view. | +| `WhatIsAWallet` | "What is a wallet" onboarding view. | +{/* Add any other views if available, and verify these from the modal\'s implementation */} + +## `useAccount()` + +This is the primary hook to access the details of the connected account. +The exact properties returned by this hook should be verified against the source code. + +```typescript +import { useAccount } from '@reown/appkit-react-native'; + +export default function MyComponent() { + const { + address, // String, the connected account address (e.g., '0x...', 'Sol...', 'bc1...') + chainId, // Number or String, the chain ID of the currently active connection + isConnected, // Boolean, true if a wallet is connected on the current chain/namespace + } = useAccount(); + + if (isConnected) { + return ( +
+

Connected to chain: {chainId}

+

Address: {address}

+
+ ); + } + return

Not Connected

; +} ``` -
- - -```ts -import { useAppKitEvents } from '@reown/appkit-ethers5-react-native' - -const event = useAppKitEvents(event => { - // your code here -}) +## `useProvider()` + +This hook provides access to the underlying chain-specific provider for the currently active connection. This is useful for performing direct interactions with the blockchain that go beyond the standard AppKit actions. + +By default, `useProvider()` returns the provider for the currently active network. You can also get a provider for a specific namespace by passing an argument, e.g., `useProvider('eip155')`, `useProvider('solana')`, or `useProvider('bitcoin')`. + +```typescript +import { useProvider, useAccount } from '@reown/appkit-react-native'; + +// Example for EVM chains (using ethers.js) +// import { BrowserProvider, JsonRpcSigner } from 'ethers'; + +// Example for Solana +// import { Connection } from '@solana/web3.js'; + +export default function ChainSpecificActions() { + // Get provider for the current active network + const { provider, providerType } = useProvider(); + // Or, to get a specific provider: + // const { provider: evmProvider, providerType: evmType } = useProvider('eip155'); + // const { provider: solanaProvider, providerType: solanaType } = useProvider('solana'); + + const { chainId, address, isConnected } = useAccount(); + + if (!isConnected || !provider) { + return

Please connect your wallet.

; + } + + const handleSignMessageEVM = async () => { + if (providerType === 'eip155' && address) { + // const ethersProvider = new BrowserProvider(provider); // Or however the provider is typed + // const signer = await ethersProvider.getSigner(); + // const signature = await signer.signMessage('Hello from AppKit!'); + // console.log('EVM Signature:', signature); + alert('EVM sign message functionality to be implemented using the provider.'); + } + }; + + const handleSignMessageSolana = async () => { + if (providerType === 'solana' && address) { + // const solanaConnection = provider as Connection; // Cast to Solana Connection + // const message = `Hello from AppKit! Address: ${address}`; + // const encodedMessage = new TextEncoder().encode(message); + // const signature = await provider.signMessage(encodedMessage, 'utf8'); // Assuming provider has signMessage + // console.log('Solana Signature:', signature); + alert('Solana sign message functionality to be implemented using the provider.'); + } + }; + + // Similar functions can be created for Bitcoin + + return ( +
+

Current Chain ID: {chainId}

+

Provider Type: {providerType || 'N/A'}

+ {providerType === 'eip155' && } + {providerType === 'solana' && } + {/* Add buttons for other provider types as needed */} +
+ ); +} ``` -
- -
- -## useAppKitEventSubscription - -Subscribe to modal specific events - - - - -```ts -import { useAppKitEventSubscription } from '@reown/appkit-wagmi-react-native' +Refer to the example usage in: +* [EVM + Ethers](https://github.com/reown-com/appkit-react-native/blob/feat/multichain/apps/native/src/views/EthersActionsView.tsx) +* [EVM + Wagmi](https://github.com/reown-com/appkit-react-native/blob/feat/multichain/apps/native/src/views/WagmiActionsView.tsx) (Note: Wagmi has its own provider/signer abstractions, so `useProvider` might be used differently or in conjunction with Wagmi's hooks) +* [Solana](https://github.com/reown-com/appkit-react-native/blob/feat/multichain/apps/native/src/views/SolanaActionsView.tsx) +* [Bitcoin](https://github.com/reown-com/appkit-react-native/blob/feat/multichain/apps/native/src/views/BitcoinActionsView.tsx) -useAppKitEventSubscription('MODAL_OPEN', newEvent => { - // your code here -}); -``` +## `useWalletInfo()` - +This hook provides metadata about the connected wallet. The exact structure of `walletInfo` can be found in the `WalletInfo` type definition in [packages/common/src/utils/TypeUtil.ts](https://github.com/reown-com/appkit-react-native/blob/f70c343eb954419ceb43c0cd922a5929d8462a56/packages/common/src/utils/TypeUtil.ts#L365). - -```ts -import { useAppKitEventSubscription } from '@reown/appkit-ethers-react-native' +```typescript +import { useWalletInfo } from '@reown/appkit-react-native'; -useAppKitEventSubscription('MODAL_OPEN', newEvent => { - // your code here -}); -``` - +export default function WalletDetails() { + const { walletInfo } = useWalletInfo(); // Verify exact return structure from source - -```ts -import { useAppKitEventSubscription } from '@reown/appkit-ethers5-react-native' + if (!walletInfo) { + return

No wallet connected or info unavailable.

; + } -useAppKitEventSubscription('MODAL_OPEN', newEvent => { - // your code here -}); + return ( +
+

Connected Wallet:

+

Name: {walletInfo.name}

+

Icon: {walletInfo.icon && {walletInfo.name}}

+ {/* Refer to TypeUtil.ts for other walletInfo properties e.g., rdns, id etc. */} +
+ ); +} ``` -
- -
- -## useWalletInfo - -Get the metadata information from the connected wallet - - - - -```ts -import { useWalletInfo } from '@reown/appkit-wagmi-react-native' - -const { walletInfo } = useWalletInfo() -```` +## `useAppKitEventSubscription()` - +AppKit emits events for various state changes and actions. You can subscribe to these events to react accordingly in your application. The full list of event types and their payloads can be found in `AppKitEvents` within [packages/core/src/utils/TypeUtil.ts](https://github.com/reown-com/appkit-react-native/blob/f70c343eb954419ceb43c0cd922a5929d8462a56/packages/core/src/utils/TypeUtil.ts#L369). +This hook provides a way to subscribe to a specific modal event and receives a callback function that is executed when the event is triggered. - -```ts -import { useWalletInfo } from '@reown/appkit-ethers-react-native' +```typescript +import { useAppKitEventSubscription } from '@reown/appkit-react-native'; -const { walletInfo } = useWalletInfo() +export default function EventLogger() { + useAppKitEventSubscription('MODAL_OPEN', event => { console.log('Modal opened!', event); }); -```` - + useAppKitEventSubscription('CONNECT_SUCCESS', event => { console.log('Wallet connected!', event); }); - -```ts -import { useWalletInfo } from '@reown/appkit-ethers5-react-native' - -const { walletInfo } = useWalletInfo() -```` - - - - - -## Ethereum Library - - - - - - + return null; +} +``` - - - +## Deprecated Hooks - - - +### `useAppKitState()` +The functionality of `useAppKitState` (which previously exposed `open` (modal state) and `selectedNetworkId`) is now incorporated into `useAppKit()` (for modal control like `isOpen`) and `useAccount()` (for `chainId`). - +### `useDisconnect()` +The functionality of `useDisconnect` (which previously exposed a `disconnect` function) is now available directly from the `useAppKit()` hook. diff --git a/appkit/react-native/core/installation.mdx b/appkit/react-native/core/installation.mdx index a758ba10c..806aa0506 100644 --- a/appkit/react-native/core/installation.mdx +++ b/appkit/react-native/core/installation.mdx @@ -3,122 +3,441 @@ title: Installation --- import CloudBanner from "/snippets/cloud-banner.mdx"; +import ExpoBabel from "/snippets/appkit/react-native/expo/babel-config-expo53.mdx" -import WagmiInstallation from "/snippets/appkit/react-native/wagmi/about/installation.mdx"; -import WagmiInstallationExpo from "/snippets/appkit/react-native/wagmi/about/installation-expo.mdx"; -import WagmiImplementation from "/snippets/appkit/react-native/wagmi/about/implementation.mdx"; -import WagmiCoinbase from "/snippets/appkit/react-native/wagmi/about/coinbase.mdx"; +AppKit for React Native enables seamless integration with multiple blockchain ecosystems, including EVM chains (like Ethereum, Polygon, etc.), Solana, and Bitcoin. It provides a unified API to manage wallet connections, interact with different chains, and build rich multi-chain applications. -import Ethers5Installation from "/snippets/appkit/react-native/ethers5/about/installation.mdx"; -import Ethers5InstallationExpo from "/snippets/appkit/react-native/ethers5/about/installation-expo.mdx"; -import Ethers5Implementation from "/snippets/appkit/react-native/ethers5/about/implementation.mdx"; -import Ethers5Coinbase from "/snippets/appkit/react-native/ethers5/about/coinbase.mdx"; - -import EthersInstallation from "/snippets/appkit/react-native/ethers/about/installation.mdx"; -import EthersInstallationExpo from "/snippets/appkit/react-native/ethers/about/installation-expo.mdx"; -import EthersImplementation from "/snippets/appkit/react-native/ethers/about/implementation.mdx"; -import EthersCoinbase from "/snippets/appkit/react-native/ethers/about/coinbase.mdx"; - -# React Native - -## Introduction - -AppKit has support for [Wagmi](https://wagmi.sh) and [Ethers](https://docs.ethers.org/v6/). Choose one of these Ethereum libraries to get started. +At the core of AppKit is a centralized `AppKit` instance that handles connection logic, manages various chain adapters, and provides data to your application via a React Context. ## Installation - - - - +Installation is a two-step process: +1. Install the core AppKit library. +2. Install the specific chain adapters you need for your application. - + + +### Core Library +```bash +npx expo install @reown/appkit-react-native@alpha @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat expo-application +``` - + + - - - - - +### Core Library - - - +Install our core library and it's dependencies +```bash +npm install @reown/appkit-react-native@alpha @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat +``` +On iOS, use CocoaPods to add the native modules to your project: - +```bash +npx pod-install +``` - - +### Chain Adapters +For React Native CLI projects, use `npm install ...` or `yarn add ...`. - +Install the adapters for the chains you intend to support: + +

For EVM-compatible chains, you can choose between the Ethers.js-based adapter or the Wagmi-based adapter. You should install the one that best fits your project's existing setup or preference.

+ + + +

This adapter uses Ethers.js for interacting with EVM chains.

+ ```bash + npx expo install @reown/appkit-ethers-react-native@alpha + ``` +

To initialize the Ethers adapter:

+ ```typescript + import { EthersAdapter } from '@reown/appkit-ethers-react-native'; + + const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + const ethersAdapter = new EthersAdapter({ projectId }); + ``` +
+ +

This adapter integrates with Wagmi for state management and EVM interactions. It requires a few more setup steps compared to the Ethers adapter.

+ +

1. Install Packages:

+

First, install the Reown Wagmi adapter and its peer dependencies:

+ ```bash + # Install the Reown Wagmi adapter + npx expo install @reown/appkit-wagmi-react-native@alpha + + # Install Wagmi and its required peer dependencies + npx expo install wagmi viem@2.x @tanstack/react-query + ``` + +

2. Configure Wagmi and Initialize Adapter:

+

The `WagmiAdapter` requires a Wagmi configuration object. You'll create this using `createConfig` from `wagmi` (we recommend aliasing it, e.g., to `createWagmiConfig`, if you also use `createConfig` from AppKit). This config, defining your chains and transports, is then passed to the `WagmiAdapter` during its initialization within your AppKit setup file (e.g., `src/AppKitConfig.ts`).

+ + ```typescript + // src/AppKitConfig.ts (or wherever you configure AppKit) + import "@walletconnect/react-native-compat"; + import { createAppKit } from '@reown/appkit-react-native'; // Assuming other AppKit imports are present + import { WagmiAdapter } from '@reown/appkit-wagmi-react-native'; + import { http, createConfig as createWagmiCoreConfig } from 'wagmi'; + import { mainnet, sepolia } from 'wagmi/chains'; // Or other chains you need + // ... other adapter imports if any + + const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + + export const wagmiAdapter = new WagmiAdapter({ + projectId, + networks: [mainnet, sepolia], // Add all chains you want to support + }); + + export const appKit = createAppKit({ + projectId, + // Add your AppKitNetwork array for 'networks' matching the wagmiCoreConfig chains + // networks: [mainnet, sepolia, ...], + adapters: [wagmiAdapter, /* other adapters for other chain types */], + // ... other AppKit options + }); + ``` + Ensure the `networks` array in `AppKit` options includes the chains defined in `wagmiAdapter`. + +

3. Set up Context Providers in App.tsx:

+

Wagmi requires its own context provider (`WagmiProvider`) and also relies on TanStack Query (`QueryClientProvider`). You'll need to wrap your application (or the relevant part of it) with these providers, in addition to the `AppKitProvider`. The `config` prop for `WagmiProvider` must be the `wagmiConfig` instance from your initialized `WagmiAdapter`. Refer to the official Wagmi documentation for details on provider setup.

+ + ```tsx + // App.tsx + import React from 'react'; + import { AppKitProvider } from '@reown/appkit-react-native'; + import { appKit, wagmiAdapter } from './AppKitConfig'; // Your configured AppKit instance + import YourAppRootComponent from './YourAppRootComponent'; // Your main app component + + import { WagmiProvider } from 'wagmi'; + import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; + + const queryClient = new QueryClient(); + + function App() { + return ( + + + + + + + + ); + } + + export default App; + ``` + +

For a practical implementation example, you can refer to the Reown AppKit + Wagmi example on GitHub.

+
+
+
+ +

For Solana, install the Solana adapter:

+ ```bash + npx expo install @reown/appkit-solana-react-native@alpha + ``` +

To initialize the Solana adapter:

+ ```typescript + import { SolanaAdapter } from '@reown/appkit-solana-react-native'; + + const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + const solanaAdapter = new SolanaAdapter({ projectId }); + ``` +
+ +

For Bitcoin, install the Bitcoin adapter:

+ ```bash + npx expo install @reown/appkit-bitcoin-react-native@alpha + ``` +

To initialize the Bitcoin adapter:

+ ```typescript + import { BitcoinAdapter } from '@reown/appkit-bitcoin-react-native'; + + const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + const bitcoinAdapter = new BitcoinAdapter({ projectId }); + ``` +
+
- +## Implementation +### 1. Initialize AppKit + +First, create an instance of `AppKit`. This is where you'll configure your project ID (if using WalletConnect features) and define the chains your application will support, along with their respective adapters. + + +To ensure proper functioning with React Native, make sure `import "@walletconnect/react-native-compat";` is the very first line in your configuration file (e.g., `AppKitConfig.ts`), even before other imports. This import handles necessary polyfills. + + +```typescript +// src/AppKitConfig.ts (or wherever you prefer to configure it) +import "@walletconnect/react-native-compat"; +import { createAppKit, bitcoin, solana, type AppKitNetwork } from '@reown/appkit-react-native'; +import { EthersAdapter } from '@reown/appkit-ethers-react-native'; +import { SolanaAdapter } from '@reown/appkit-solana-react-native'; +import { BitcoinAdapter } from '@reown/appkit-bitcoin-react-native'; + +// You can use 'viem/chains' or define your own chains using `AppKitNetwork` type. Check Options/networks for more detailed info +import { mainnet, polygon } from 'viem/chains'; + +const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + +const ethersAdapter = new EthersAdapter({ + projectId +}); + +const solanaAdapter = new SolanaAdapter({ + projectId +}); + +const bitcoinAdapter = new BitcoinAdapter({ + projectId +}); + +export const appKit = createAppKit({ + projectId, + networks: [mainnet, polygon, solana, bitcoin], + defaultNetwork: mainnet, // Optional: set a default network + adapters: [ethersAdapter, solanaAdapter, bitcoinAdapter], + + // Other AppKit options (e.g., metadata for your dApp) + metadata: { + name: 'My Awesome dApp', + description: 'My dApp description', + url: 'https://myapp.com', + icons: ['https://myapp.com/icon.png'], + redirect: { + native: "YOUR_APP_SCHEME://", + universal: "YOUR_APP_UNIVERSAL_LINK.com", + }, + } +}); +``` +### 2. Provide AppKit Instance - +Wrap your application with the `AppKitProvider` to make the `AppKit` instance available throughout your component tree via context. - +```tsx {3,9} +// App.tsx +import React from 'react'; +import { AppKitProvider } from '@reown/appkit-react-native'; +import { appKit } from './AppKitConfig'; // Your configured AppKit instance +import YourAppRootComponent from './YourAppRootComponent'; - +function App() { + return ( + + + + ); +} +export default App; +``` +### 3. Render AppKit UI - +To display the AppKit modal and other potential UI elements, you need to include the `` component in your application. If you want the modal to be accessible from anywhere in your app, it's best to place this component within your main application root component (e.g., the `YourAppRootComponent` from the example above, or directly in `App.tsx` if it serves as your main layout). - +```tsx {3,15} +// YourAppRootComponent.tsx (or App.tsx if it contains your main layout) +import React from 'react'; +import { AppKit } from '@reown/appkit-react-native'; +// ... other imports for your app components like ConnectButton, etc. +import ConnectButton from './components/ConnectButton'; // Example import - +function YourAppRootComponent() { + return ( + <> + {/* Your application's content */} + + {/* ... other components ... */} + {/* Add the AppKit component here to render its UI (e.g., the modal) */} + + + ); +} +export default YourAppRootComponent; +``` - +### 4. Using AppKit in Components - +You can now access AppKit functionalities (like connecting, getting account state, etc.) using hooks provided by the library. -
+```tsx +// components/ConnectButton.tsx +import { useAppKit, useAccount } from '@reown/appkit-react-native'; + +function ConnectButton() { + const { open, disconnect } = useAppKit(); + const { address, isConnected, chainId } = useAccount(); + + if (isConnected) { + return ( +
+

Connected to: {chainId}

+

Address: {address}

+ +
+ ); + } -
+ return ; +} -
+export default ConnectButton; +``` +For detailed examples on specific actions like signing messages, sending transactions, or switching networks, please refer to the [Hooks](./hooks#useprovider) and [Examples](#examples) sections. + +### 5. Configure Storage + +For data to persist across sessions, you need to provide a storage solution. The `createAppKit` function accepts a `storage` option that must conform to the `Storage` interface. + +The `Storage` interface, which can be imported from `@reown/appkit-react-native`, is defined as follows: + +```typescript +export interface Storage { + /** + * Returns all keys in storage. + */ + getKeys(): Promise; + + /** + * Returns all key-value entries in storage. + */ + getEntries(): Promise<[string, T][]>; + + /** + * Get an item from storage for a given key. + * @param key The key to retrieve. + */ + getItem(key: string): Promise; + + /** + * Set an item in storage for a given key. + * @param key The key to set. + * @param value The value to set. + */ + setItem(key: string, value: T): Promise; + + /** + * Remove an item from storage for a given key. + * @param key The key to remove. + */ + removeItem(key: string): Promise; +} +``` -## Implementation +**Example with AsyncStorage** - +You can implement this interface using a library like `@react-native-async-storage/async-storage`. Create a new file, for example `src/StorageUtil.ts`, with the following content: - - - +```typescript +// src/StorageUtil.ts +import AsyncStorage from '@react-native-async-storage/async-storage'; +import { safeJsonParse, safeJsonStringify } from '@walletconnect/safe-json'; +import type { Storage } from '@reown/appkit-react-native'; - - - - - - - - - +export const storage: Storage = { + getKeys: async () => { + return AsyncStorage.getAllKeys() as Promise; + }, + getEntries: async (): Promise<[string, T][]> => { + function parseEntry(entry: [string, string | null]): [string, any] { + return [entry[0], safeJsonParse(entry[1] ?? '')]; + } -## Getting Support 🙋 + const keys = await AsyncStorage.getAllKeys(); + const entries = await AsyncStorage.multiGet(keys); + + return entries.map(parseEntry); + }, + setItem: async (key: string, value: any) => { + return await AsyncStorage.setItem(key, safeJsonStringify(value)); + }, + getItem: async (key: string): Promise => { + const item = await AsyncStorage.getItem(key); + if (typeof item === 'undefined' || item === null) { + return undefined; + } -Reown is committed to delivering the best developer experience. + return safeJsonParse(item) as T; + }, + removeItem: async (key: string) => { + return await AsyncStorage.removeItem(key); + } +}; +``` -If you have any questions, feature requests, or bug reports, feel free to open an issue on [GitHub](https://github.com/reown-com/appkit-react-native)! +**Update AppKit Configuration** + +Finally, import your custom storage and pass it to `createAppKit` in your `AppKitConfig.ts`. This example builds on the configuration from [Initialize AppKit](#1-initialize-appkit): + +```typescript {7,31} +// src/AppKitConfig.ts (or wherever you prefer to configure it) +import "@walletconnect/react-native-compat"; +import { createAppKit, bitcoin, solana, type AppKitNetwork } from '@reown/appkit-react-native'; +import { EthersAdapter } from '@reown/appkit-ethers-react-native'; +import { SolanaAdapter } from '@reown/appkit-solana-react-native'; +import { BitcoinAdapter } from '@reown/appkit-bitcoin-react-native'; +import { storage } from './StorageUtil'; // 1. Import your custom storage + +// You can use 'viem/chains' or define your own chains using `AppKitNetwork` type. Check Options/networks for more detailed info +import { mainnet, polygon } from 'viem/chains'; + +const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud + +const ethersAdapter = new EthersAdapter({ + projectId +}); + +const solanaAdapter = new SolanaAdapter({ + projectId +}); + +const bitcoinAdapter = new BitcoinAdapter({ + projectId +}); + +export const appKit = createAppKit({ + projectId, + networks: [mainnet, polygon, solana, bitcoin], + defaultNetwork: mainnet, + adapters: [ethersAdapter, solanaAdapter, bitcoinAdapter], + storage, + + // Other AppKit options (e.g., metadata for your dApp) + metadata: { + name: 'My Awesome dApp', + description: 'My dApp description', + url: 'https://myapp.com', + icons: ['https://myapp.com/icon.png'], + redirect: { + native: "YOUR_APP_SCHEME://", + universal: "YOUR_APP_UNIVERSAL_LINK.com", + }, + } +}); +``` ## Enable Wallet Detection (Optional) @@ -132,57 +451,8 @@ If you have any questions, feature requests, or bug reports, feel free to open a To enable AppKit to detect wallets installed on the device, you can make specific changes to the native code of your project. - - - - - -1. Open your `Info.plist` file. -2. Locate the `LSApplicationQueriesSchemes` section. -3. Add the desired wallet schemes as string entries within the ``. These schemes represent the wallets you want to detect. -4. Refer to our [Info.plist example file](https://github.com/WalletConnect/react-native-examples/blob/main/dapps/ModalUProvider/ios/ModalUProvider/Info.plist) for a detailed illustration. - -Example: - -```xml -LSApplicationQueriesSchemes - - metamask - trust - safe - rainbow - uniswap - - -``` - - - - - -1. Open your `AndroidManifest.xml` file. -2. Locate the `` section. -3. Add the desired wallet package names as `` entries within the ``. These package names correspond to the wallets you want to detect. -4. Refer to our [AndroidManifest.xml example file](https://github.com/WalletConnect/react-native-examples/blob/main/dapps/ModalUProvider/android/app/src/main/AndroidManifest.xml) for detailed guidance. - -Example: - -```xml - - - - - - - -``` - - - - - - - + + @@ -280,122 +550,114 @@ module.exports = createRunOncePlugin( - - - -## Enable Coinbase Wallet (Optional) - - -**Coinbase Wallet support is optional.** Unlike other wallets that use the WalletConnect protocol, Coinbase Wallet uses its own proprietary SDK. If you skip this setup, Coinbase Wallet simply won't appear in your wallet list, but all other wallets will work normally. - + - - -Follow these steps to install Coinbase SDK in your project along with our Coinbase package. Check here for more detailed information. + +1. Open your `Info.plist` file. +2. Locate the `LSApplicationQueriesSchemes` section. +3. Add the desired wallet schemes as string entries within the ``. These schemes represent the wallets you want to detect. +4. Refer to our [Info.plist example file](https://github.com/WalletConnect/react-native-examples/blob/main/dapps/ModalUProvider/ios/ModalUProvider/Info.plist) for a detailed illustration. -1. Enable Expo Modules in your project running: +Example: -``` -npx install-expo-modules@latest +```xml +LSApplicationQueriesSchemes + + metamask + trust + safe + rainbow + uniswap + + ``` -2. Install Coinbase SDK + -``` -yarn add @coinbase/wallet-mobile-sdk react-native-mmkv -``` + -3. Install our custom connector +1. Open your `AndroidManifest.xml` file. +2. Locate the `` section. +3. Add the desired wallet package names as `` entries within the ``. These package names correspond to the wallets you want to detect. +4. Refer to our [AndroidManifest.xml example file](https://github.com/WalletConnect/react-native-examples/blob/main/dapps/ModalUProvider/android/app/src/main/AndroidManifest.xml) for detailed guidance. - +Example: - - ``` yarn add @reown/appkit-coinbase-wagmi-react-native ``` - +```xml + + + + + + + +``` - - ``` yarn add @reown/appkit-coinbase-ethers-react-native ``` + - - ``` yarn add @reown/appkit-coinbase-ethers-react-native ``` -4. Run pod-install +## Enable Phantom Wallet (Optional) -``` -npx pod-install -``` +Phantom Wallet is a popular wallet on the Solana blockchain. Because it uses a custom connection protocol, it requires a specific connector to be added to your AppKit configuration. -5. Enable Deeplink handling in your project following React Native docs +To enable Phantom Wallet, you'll need to import the `PhantomConnector` from `@reown/appkit-solana-react-native` and add it to the `extraConnectors` array in your `createAppKit` configuration. -6. Add Coinbase package in your AndroidManifest.xml and Info.Plist +Here's how to update your `AppKitConfig.ts` file, using the example from the [Implementation](#1-initialize-appkit) section as a base: -```xml -// AndroidManifest.xml +```typescript {5,30-40} +// src/AppKitConfig.ts (or wherever you prefer to configure it) +import "@walletconnect/react-native-compat"; +import { createAppKit, bitcoin, solana, type AppKitNetwork } from '@reown/appkit-react-native'; +import { EthersAdapter } from '@reown/appkit-ethers-react-native'; +import { SolanaAdapter, PhantomConnector } from '@reown/appkit-solana-react-native'; +import { BitcoinAdapter } from '@reown/appkit-bitcoin-react-native'; - - - - -``` +// You can use 'viem/chains' or define your own chains using `AppKitNetwork` type. Check Options/networks for more detailed info +import { mainnet, polygon } from 'viem/chains'; -```xml -// Info.plist +const projectId = 'YOUR_PROJECT_ID'; // Obtain from Cloud -LSApplicationQueriesSchemes - - - cbwallet - -``` +const ethersAdapter = new EthersAdapter({ + projectId +}); -7. Add Coinbase response handler in your app. More info here +const solanaAdapter = new SolanaAdapter({ + projectId +}); -```tsx -import { handleResponse } from "@coinbase/wallet-mobile-sdk"; - -// Your app's deeplink handling code -useEffect(() => { - const sub = Linking.addEventListener("url", ({ url }) => { - const handledBySdk = handleResponse(new URL(url)); - if (!handledBySdk) { - // Handle other deeplinks - } - }); +const bitcoinAdapter = new BitcoinAdapter({ + projectId +}); - return () => sub.remove(); -}, []); +export const appKit = createAppKit({ + projectId, + networks: [mainnet, polygon, solana, bitcoin], + defaultNetwork: mainnet, // Optional: set a default network + adapters: [ethersAdapter, solanaAdapter, bitcoinAdapter], + extraConnectors: [ + new PhantomConnector({ cluster: 'mainnet-beta' }) // Or 'devnet', 'testnet' + ], + customWallets: [ + { + id: 'phantom-wallet', + name: 'Phantom', + image_url: 'https://avatars.githubusercontent.com/u/124594793?s=200&v=4', + mobile_link: 'phantom://', + } + ] + // Other AppKit options (e.g., metadata for your dApp) +}); ``` - - - - - - - - - - - - - - - - -Check Coinbase docs for more detailed information. + +The `cluster` option in `PhantomConnector` can be set to `'mainnet-beta'`, `'devnet'`, or `'testnet'` depending on which Solana cluster you want to connect to. + - - - - Coinbase SDK doesn't support Expo Projects. More info here - - - ## Examples @@ -440,24 +702,8 @@ Want to see AppKit in action? Download our sample AppKit apps below and explore - [Android Build (Firebase)](https://appdistribution.firebase.google.com/pub/i/0297fbd3de8f1e3f) - [iOS Build (Testflight)](https://testflight.apple.com/join/YW2jD2s0) -## Tutorial - -
-