> ## 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.

# Setup

> Configure Privy with Base Account for your React application

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>;
};

Learn how to set up Privy with Base Account to enable seamless user authentication and wallet management.

## Overview

[Privy](https://www.privy.io/) provides user authentication and wallet management solutions for onchain applications.
By integrating Privy with Base Account,
you can access all the Privy hooks and methods
while having access to the users of Base Account.

### What you'll achieve

By the end of this guide, you will:

* Set up Privy with Base Account support
* Have Base Account set up as the main authentication option
* Be able to access Base Account SDK from Privy's React SDK

You can jump ahead and use the [Base Account Privy Template](https://github.com/base/base-account-privy) to get started.

<GithubRepoCard title="Base Account Privy Template" githubUrl="https://github.com/base/base-account-privy" />

## Installation

### 1. Create a new Next.js project

<CodeGroup>
  ```bash npm theme={null}
  npx create-next-app@latest base-account-privy
  cd base-account-privy
  ```

  ```bash yarn theme={null}
  yarn create next-app base-account-privy
  cd base-account-privy
  ```
</CodeGroup>

### 2. Override the Base Account SDK version

In order to access the latest version of the Base Account SDK, you need to override the Privy pinned version in your package.json file.

To do this, you can use the following command to override it:

<CodeGroup>
  ```bash npm theme={null}
  npm pkg set overrides.@base-org/account="latest"
  # OR manually add to package.json:
  # "overrides": { "@base-org/account": "latest" }
  ```

  ```bash pnpm theme={null}
  # pnpm requires manual addition to package.json:
  # "pnpm": { "overrides": { "@base-org/account": "latest" } }
  ```

  ```bash yarn theme={null}
  # yarn uses resolutions - add manually to package.json:
  # "resolutions": { "@base-org/account": "latest" }
  ```

  ```bash bun theme={null}
  # bun supports overrides - add manually to package.json:
  # "overrides": { "@base-org/account": "latest" }
  ```
</CodeGroup>

Or you can use a specific version by adding the version to the overrides:

<CodeGroup>
  ```bash npm theme={null}
  npm pkg set overrides.@base-org/account="2.2.0"
  # OR manually add to package.json:
  # "overrides": { "@base-org/account": "2.2.0" }
  ```

  ```bash pnpm theme={null}
  # pnpm requires manual addition to package.json:
  # "pnpm": { "overrides": { "@base-org/account": "2.2.0" } }
  ```

  ```bash yarn theme={null}
  # yarn uses resolutions - add manually to package.json:
  # "resolutions": { "@base-org/account": "2.2.0" }
  ```

  ```bash bun theme={null}
  # bun supports overrides - add manually to package.json:
  # "overrides": { "@base-org/account": "2.2.0" }
  ```
</CodeGroup>

<Tip>
  **If you're not starting a new projects**

  Make sure to delete your `node_modules` and `package-lock.json` and run a new install to ensure the overrides are applied.
</Tip>

### 3. Install the dependencies

Install the dependencies with your package manager of choice:

<CodeGroup>
  ```bash npm theme={null}
  npm install @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
  ```

  ```bash pnpm theme={null}
  pnpm add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
  ```

  ```bash yarn theme={null}
  yarn add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
  ```

  ```bash bun theme={null}
  bun add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
  ```
</CodeGroup>

## Configuration

### 1. Set up Environment Variables

Create a `.env.local` file in your project root:

```bash theme={null}
NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_id
```

Get your Privy App ID from the [Privy Dashboard](https://dashboard.privy.io/).

### 2. Configure Privy Provider

Create your Privy configuration with Base Account as the default login method and update the layout to include the `PrivyProvider`.

<CodeGroup>
  ```tsx Create Provider (app/providers.tsx) expandable theme={null}
  "use client";

  import { PrivyProvider } from "@privy-io/react-auth";
  import { base } from "@privy-io/chains";

  export default function Providers({ children }: { children: React.ReactNode }) {
    return (
      <PrivyProvider
        appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID!}
        config={{
          appearance: {
            walletList: ['base_account'],
            showWalletLoginFirst: true
          },
          defaultChain: base,
        }}
      >
        {children}
      </PrivyProvider>
    );
  }
  ```

  ```tsx Add to Layout (app/layout.tsx) expandable theme={null}
  import type { Metadata } from "next";
  import { Geist, Geist_Mono } from "next/font/google";
  import "./globals.css";
  import Providers from "./providers";

  const geistSans = Geist({
    variable: "--font-geist-sans",
    subsets: ["latin"],
  });

  const geistMono = Geist_Mono({
    variable: "--font-geist-mono",
    subsets: ["latin"],
  });

  export const metadata: Metadata = {
    title: "Privy Next demo",
    description: "Generated by create next app",
  };

  export default function RootLayout({
    children,
  }: Readonly<{
    children: React.ReactNode;
  }>) {
    return (
      <html lang="en">
        <body
          className={`${geistSans.variable} ${geistMono.variable} antialiased`}
        >
          <Providers>{children}</Providers>
        </body>
      </html>
    );
  }
  ```
</CodeGroup>

## Usage

### 1. Update the App Page

Update the `app/page.tsx` file to show the authentication flow:

```tsx app/page.tsx expandable theme={null}
"use client";

import { usePrivy } from "@privy-io/react-auth";
import { ToastContainer } from "react-toastify";

function Home() {
  const { ready, authenticated, logout, login } = usePrivy();
  if (!ready) {
    return <div>Loading...</div>;
  }

  return (
    <div className="bg-white md:max-h-[100vh] md:overflow-hidden">
      {authenticated ? (
        <section className="w-full flex flex-col md:flex-row md:h-[calc(100vh-60px)]">
          <div className="flex-grow overflow-y-auto h-full p-4 pl-8">
            <button className="button" onClick={logout}>Logout</button>
          </div>
        </section>
      ) : (
        <section className="w-full flex flex-row justify-center items-center h-[calc(100vh-60px)] relative bg-gradient-to-b from-blue-600 to-blue-700">
          <div className="z-10 flex flex-col items-center justify-center w-full h-full px-4">
          <div className="flex h-10 items-center justify-center rounded-[20px] border border-white/20 bg-white/10 backdrop-blur-sm px-6 text-lg text-white font-abc-favorit">
            Base × Privy Demo
          </div>
        <div className="text-center mt-4 text-white text-7xl font-medium font-abc-favorit leading-[81.60px]">
          Build on Base
        </div>
            <div className="text-center text-white/90 text-xl font-normal leading-loose mt-8 max-w-2xl">
              Get started building on Base with Privy&apos;s authentication and native Base Account support
            </div>
            <button
              className="bg-white text-black mt-15 w-full max-w-md rounded-full px-4 py-2 font-medium hover:bg-gray-50 transition-colors lg:px-8 lg:py-4 lg:text-xl"
              onClick={() => {
                login();
                setTimeout(() => {
                  (document.querySelector('input[type="email"]') as HTMLInputElement)?.focus();
                }, 150);
              }}
            >
              Get started
            </button>
          </div>
        </section>
      )}
  
      <ToastContainer
        position="top-center"
        autoClose={5000}
        hideProgressBar
        newestOnTop={false}
        closeOnClick={false}
        rtl={false}
        pauseOnFocusLoss
        draggable={false}
        pauseOnHover
        limit={1}
        aria-label="Toast notifications"
        style={{ top: 58 }}
      />
    </div>
  );
}

export default Home;
```

### 2. Run the project locally

You're done! You can now run the project locally:

<CodeGroup>
  ```bash npm theme={null}
  npm run dev
  ```

  ```bash pnpm theme={null}
  pnpm dev
  ```

  ```bash yarn theme={null}
  yarn dev
  ```

  ```bash bun theme={null}
  bun dev
  ```
</CodeGroup>

You should see a page that looks like this:

<div style={{ display: 'flex', justifyContent: 'center'}}>
  <img src="https://mintcdn.com/base-a060aa97/k2t1UOHQWAcdoYwb/images/base-account/Privy-Base-Account.png?fit=max&auto=format&n=k2t1UOHQWAcdoYwb&q=85&s=448e7791d71193b0f9f546bbcd328a98" alt="Base × Privy Demo" style={{ width: '600px', height: 'auto' }} width="963" height="681" data-path="images/base-account/Privy-Base-Account.png" />
</div>

### 3. Get the Base Account SDK instance (Optional)

You can access the Base Account SDK from Privy using the `useBaseAccount` hook.

```tsx Get the SDK instance theme={null}
import { useBaseAccountSdk } from '@privy-io/react-auth';

const { baseAccountSdk } = useBaseAccountSdk();

const provider = baseAccountSdk.getProvider();

const addresses = await provider.request({method: 'wallet_connect'});

```
