@@ -31,31 +31,22 @@ You can jump ahead and use the [Base Account Privy Template](https://github.com/
3131
3232## Installation
3333
34- After [ creating a new Next.js project] ( https://nextjs.org/docs/app/getting-started/installation ) , install the required dependencies:
35-
34+ ### 1. Create a new Next.js project
3635<CodeGroup >
3736``` bash npm
38- npm install @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account @base-org/account-ui
39- ```
40-
41- ``` bash pnpm
42- pnpm add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account @base-org/account-ui
37+ npx create-next-app@latest base-account-privy
38+ cd base-account-privy
4339```
4440
4541``` bash yarn
46- yarn add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account @base-org/account-ui
42+ yarn create next-app base-account-privy
43+ cd base-account-privy
4744```
48-
49- ``` bash bun
50- bun add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account @base-org/account-ui
51- ```
52-
5345</CodeGroup >
5446
55- <Tip >
56- ** Access the latest version of the Base Account SDK (Recommended)**
47+ ### 2. Override the Base Account SDK version
5748
58- It is { < u >HIGHLY RECOMMENDED</ u > } to access the latest version of the Base Account SDK in order to get the latest features and bug fixes .
49+ 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 .
5950
6051To do this, you can use the following command to override it:
6152
@@ -109,10 +100,35 @@ npm pkg set overrides.@base-org/account="2.2.0"
109100
110101</CodeGroup >
111102
112- Make sure to delete your ` node_modules ` and ` package-lock.json ` and run a new install to ensure the overrides are applied.
103+ <Tip >
104+ ** If you're not starting a new projects**
113105
106+ Make sure to delete your ` node_modules ` and ` package-lock.json ` and run a new install to ensure the overrides are applied.
114107</Tip >
115108
109+ ### 3. Install the dependencies
110+
111+ Install the dependencies with your package manager of choice:
112+
113+ <CodeGroup >
114+ ``` bash npm
115+ npm install @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
116+ ```
117+
118+ ``` bash pnpm
119+ pnpm add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
120+ ```
121+
122+ ``` bash yarn
123+ yarn add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
124+ ```
125+
126+ ``` bash bun
127+ bun add @privy-io/react-auth @privy-io/chains @privy-io/wagmi-connector wagmi viem @base-org/account-ui react-toastify
128+ ```
129+
130+ </CodeGroup >
131+
116132## Configuration
117133
118134### 1. Set up Environment Variables
@@ -127,10 +143,10 @@ Get your Privy App ID from the [Privy Dashboard](https://dashboard.privy.io/).
127143
128144### 2. Configure Privy Provider
129145
130- Create your Privy configuration with Base Account and email as login methods:
146+ Create your Privy configuration with Base Account as the default login method and update the layout to include the ` PrivyProvider ` .
131147
132148<CodeGroup >
133- ``` tsx Create Provider (providers /providers.tsx)
149+ ``` tsx Create Provider (app /providers.tsx) expandable
134150" use client" ;
135151
136152import { PrivyProvider } from " @privy-io/react-auth" ;
@@ -140,7 +156,6 @@ export default function Providers({ children }: { children: React.ReactNode }) {
140156 return (
141157 <PrivyProvider
142158 appId = { process .env .NEXT_PUBLIC_PRIVY_APP_ID ! }
143- clientId = { process .env .NEXT_PUBLIC_PRIVY_CLIENT_ID ! }
144159 config = { {
145160 appearance: {
146161 walletList: [' base_account' ],
@@ -154,11 +169,11 @@ export default function Providers({ children }: { children: React.ReactNode }) {
154169 );
155170}
156171```
157- ``` tsx Add to Layout (app/layout.tsx)
172+ ``` tsx Add to Layout (app/layout.tsx) expandable
158173import type { Metadata } from " next" ;
159174import { Geist , Geist_Mono } from " next/font/google" ;
160175import " ./globals.css" ;
161- import Providers from " @/providers /providers" ;
176+ import Providers from " . /providers" ;
162177
163178const geistSans = Geist ({
164179 variable: " --font-geist-sans" ,
@@ -193,7 +208,106 @@ export default function RootLayout({
193208```
194209</CodeGroup >
195210
196- ### 3. Access Base Account SDK from Privy
211+ ## Usage
212+
213+ ### 1. Update the App Page
214+
215+ Update the ` app/page.tsx ` file to show the authentication flow:
216+
217+ ``` tsx app/page.tsx expandable
218+ " use client" ;
219+
220+ import { usePrivy } from " @privy-io/react-auth" ;
221+ import { ToastContainer } from " react-toastify" ;
222+
223+ function Home() {
224+ const { ready, authenticated, logout, login } = usePrivy ();
225+ if (! ready ) {
226+ return <div >Loading...</div >;
227+ }
228+
229+ return (
230+ <div className = " bg-white md:max-h-[100vh] md:overflow-hidden" >
231+ { authenticated ? (
232+ <section className = " w-full flex flex-col md:flex-row md:h-[calc(100vh-60px)]" >
233+ <div className = " flex-grow overflow-y-auto h-full p-4 pl-8" >
234+ <button className = " button" onClick = { logout } >Logout</button >
235+ </div >
236+ </section >
237+ ) : (
238+ <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" >
239+ <div className = " z-10 flex flex-col items-center justify-center w-full h-full px-4" >
240+ <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" >
241+ Base × Privy Demo
242+ </div >
243+ <div className = " text-center mt-4 text-white text-7xl font-medium font-abc-favorit leading-[81.60px]" >
244+ Build on Base
245+ </div >
246+ <div className = " text-center text-white/90 text-xl font-normal leading-loose mt-8 max-w-2xl" >
247+ Get started building on Base with Privy' s authentication and native Base Account support
248+ </div >
249+ <button
250+ 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"
251+ onClick = { () => {
252+ login ();
253+ setTimeout (() => {
254+ (document .querySelector (' input[type="email"]' ) as HTMLInputElement )?.focus ();
255+ }, 150 );
256+ }}
257+ >
258+ Get started
259+ </button >
260+ </div >
261+ </section >
262+ )}
263+
264+ <ToastContainer
265+ position = " top-center"
266+ autoClose = { 5000 }
267+ hideProgressBar
268+ newestOnTop = { false }
269+ closeOnClick = { false }
270+ rtl = { false }
271+ pauseOnFocusLoss
272+ draggable = { false }
273+ pauseOnHover
274+ limit = { 1 }
275+ aria-label = " Toast notifications"
276+ style = { { top: 58 }}
277+ />
278+ </div >
279+ );
280+ }
281+
282+ export default Home ;
283+ ```
284+
285+ ### 2. Run the project locally
286+
287+ You're done! You can now run the project locally:
288+
289+ <CodeGroup >
290+ ``` bash npm
291+ npm run dev
292+ ```
293+ ``` bash pnpm
294+ pnpm dev
295+ ```
296+ ``` bash yarn
297+ yarn dev
298+ ```
299+ ``` bash bun
300+ bun dev
301+ ```
302+ </CodeGroup >
303+
304+ You should see a page that looks like this:
305+
306+ <div style = { { display: ' flex' , justifyContent: ' center' }} >
307+ <img src = " /images/base-account/Privy-Base-Account.png" alt = " Base × Privy Demo" style = { { width: ' 600px' , height: ' auto' }} />
308+ </div >
309+
310+ ### 3. Get the Base Account SDK instance (Optional)
197311
198312You can access the Base Account SDK from Privy using the ` useBaseAccount ` hook.
199313
0 commit comments