> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Mobile (React Native)

export const GithubRepoCard = ({title, githubUrl}) => {
  return <a href={githubUrl} target="_blank" rel="noopener noreferrer" className="mb-4 flex items-center rounded-lg bg-zinc-900 p-4 text-white transition-all hover:bg-zinc-800">
      <div className="flex w-full items-center gap-3">
        <svg height="24" width="24" className="flex-shrink-0 dark:fill-white" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
          <path fill="currentColor" fillRule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
        </svg>

        <div className="flex min-w-0 flex-grow flex-col">
          <span className="truncate text-base font-medium">{title}</span>
          <span className="truncate text-xs text-zinc-400">{githubUrl}</span>
        </div>

        <svg className="h-5 w-5 flex-shrink-0 text-zinc-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
        </svg>
      </div>
    </a>;
};

export const Danger = ({children}) => {
  return <div class="my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border danger-admonition dark:danger-admonition">
      <div class="mt-0.5 w-4">
        <svg width="14" height="14" viewBox="0 0 14 14" fill="rgb(239, 68, 68)" xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-sky-500" aria-label="Danger">
          <path fill-rule="evenodd" clip-rule="evenodd" d="M7 1.3C10.14 1.3 12.7 3.86 12.7 7C12.7 10.14 10.14 12.7 7 12.7C5.48908 12.6974 4.0408 12.096 2.97241 11.0276C1.90403 9.9592 1.30264 8.51092 1.3 7C1.3 3.86 3.86 1.3 7 1.3ZM7 0C3.14 0 0 3.14 0 7C0 10.86 3.14 14 7 14C10.86 14 14 10.86 14 7C14 3.14 10.86 0 7 0ZM8 3H6V8H8V3ZM8 9H6V11H8V9Z"></path>
        </svg>
      </div>
      <div class="text-sm prose min-w-0">
        {children}
      </div>
    </div>;
};

This guide helps you add support for Base Account into a React Native app
by integrating the
[Mobile Wallet Protocol Client](https://www.npmjs.com/package/@mobile-wallet-protocol/client).

<Note>
  This doc is updated for Mobile Wallet Protocol Client `v1.0.0`
</Note>

<Danger>
  **Deep Link Handling**

  Breaking change in v1.0.0: Universal Links and App Links requirements are
  removed in favor of custom schemes (e.g. `myapp://`).
</Danger>

## Before You Start

This guide walks you through adding support for Base Account into an existing React Native app or starter project.

If you prefer to skip ahead and start with a working example, navigate to the repository below:

<GithubRepoCard title="Mobile Wallet Protocol Expo Example" githubUrl="https://github.com/MobileWalletProtocol/smart-wallet-expo-example" />

If you are looking to integrate Base Account into an existing React Native app or starter project, follow the instructions below.

## Step 1: Install Mobile Wallet Protocol Client

Add the latest version of [Mobile Wallet Protocol Client](https://mobilewalletprotocol.github.io/wallet-mobile-sdk/) to your project.

<CodeGroup>
  ```zsh npm theme={null}
  npm i @mobile-wallet-protocol/client@latest
  ```

  ```zsh yarn theme={null}
  yarn add @mobile-wallet-protocol/client@latest
  ```
</CodeGroup>

## Step 2: Add Polyfills

### Install peer dependencies

The Mobile Wallet Protocol Client library requires the [Expo WebBrowser](https://docs.expo.dev/versions/latest/sdk/webbrowser/) and [Async Storage](https://react-native-async-storage.github.io/2.0/Installation/) packages to be installed.
Follow the instructions on the respective pages for any additional setup.

<CodeGroup>
  ```zsh npm theme={null}
  npm i expo expo-web-browser @react-native-async-storage/async-storage
  ```

  ```zsh yarn theme={null}
  yarn add expo expo-web-browser @react-native-async-storage/async-storage
  ```
</CodeGroup>

### Polyfills

Mobile Wallet Protocol Client requires `crypto.randomUUID`, `crypto.getRandomValues`, and `URL` to be polyfilled globally since they are not available in the React Native environment.

Below is an example of how to polyfill these functions in your app using the [expo-crypto](https://docs.expo.dev/versions/latest/sdk/crypto/) and [expo-standard-web-crypto](https://github.com/expo/expo/tree/master/packages/expo-standard-web-crypto/) packages.

<CodeGroup>
  ```zsh npm theme={null}
  npm i expo-crypto expo-standard-web-crypto react-native-url-polyfill
  ```

  ```zsh yarn theme={null}
  yarn add expo-crypto expo-standard-web-crypto react-native-url-polyfill
  ```
</CodeGroup>

<CodeGroup>
  ```js polyfills.js theme={null}
  import "react-native-url-polyfill/auto";
  import { polyfillWebCrypto } from "expo-standard-web-crypto";
  import { randomUUID } from "expo-crypto";

  polyfillWebCrypto();
  crypto.randomUUID = randomUUID;
  ```

  ```tsx App.tsx theme={null}
  import "./polyfills"; // import before @mobile-wallet-protocol/client

  import { CoinbaseWalletSDK } from "@mobile-wallet-protocol/client";

  /// ...
  ```
</CodeGroup>

## Step 3: Usage

Mobile Wallet Protocol Client provides 2 interfaces for mobile app to interact with the Base Account, an EIP-1193 compliant provider interface and a wagmi connector.

<Check>
  If your app is using wallet aggregator, go straight to [**Option 2: Wagmi
  Connector**](#option-2-wagmi-connector) for 1-line integration.
</Check>

### Option 1: EIP-1193 Provider

<Warning>
  The `app` prefix in SDK config params is removed in v1.0.0.
</Warning>

Create a new `EIP1193Provider` instance, which is EIP-1193 compliant.

```tsx App.tsx theme={null}
import { EIP1193Provider } from "@mobile-wallet-protocol/client";

// Step 1. Initialize provider with your dapp's metadata and target wallet
const metadata = {
  name: "My App Name",
  customScheme: "myapp://", // only custom scheme (e.g. `myapp://`) is supported in v1.0.0
  chainIds: [8453],
  logoUrl: "https://example.com/logo.png",
};
const provider = new EIP1193Provider({
  metadata,
  wallet: Wallets.CoinbaseSmartWallet,
});

// ...

// 2. Use the provider
const addresses = await provider.request({ method: "eth_requestAccounts" });
const signedData = await provider.request({
  method: "personal_sign",
  params: ["0x48656c6c6f20776f726c6421", addresses[0]],
});
```

### Option 2: Wagmi Connector

Add the latest version of Mobile Wallet Protocol wagmi-connectors to your project.

<CodeGroup>
  ```zsh npm theme={null}
  npm i @mobile-wallet-protocol/wagmi-connectors@latest
  ```

  ```zsh yarn theme={null}
  yarn add @mobile-wallet-protocol/wagmi-connectors@latest
  ```
</CodeGroup>

Simply import the `createConnectorFromWallet` function and pass in the wallet you want to use to wagmi config.

```ts config.ts theme={null}
import {
  createConnectorFromWallet,
  Wallets,
} from "@mobile-wallet-protocol/wagmi-connectors";

const metadata = {
  name: "My App Name",
  customScheme: "myapp://", // only custom scheme (e.g. `myapp://`) is supported in v1.0.0
  chainIds: [8453],
  logoUrl: "https://example.com/logo.png",
};

export const config = createConfig({
  chains: [base],
  connectors: [
    createConnectorFromWallet({
      metadata,
      wallet: Wallets.CoinbaseSmartWallet,
    }),
  ],
  transports: {
    [base.id]: http(),
  },
});
```

Then you can use wagmi's react interface to interact with the Base Account.

```tsx App.tsx theme={null}
import { useConnect } from "wagmi";

// ...

const { connect, connectors } = useConnect();

return (
  <Button
    title={"Connect"}
    onPress={() => {
      connect({ connector: connectors[0] });
    }}
  />
);
```

## Give feedback!

Send us feedback on the [Base Discord](https://discord.com/invite/buildonbase/) or create a new issue on the [MobileWalletProtocol/react-native-client](https://github.com/MobileWalletProtocol/react-native-client/issues) repository.
