Skip to content

Commit d6dd546

Browse files
committed
feat: add Privy wallet generation API and integrate Privy context provider
2 parents 3214941 + da7898a commit d6dd546

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

app/api/generateWallet/route.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PrivyClient } from "@privy-io/server-auth";
2+
import { type NextRequest, NextResponse } from "next/server";
3+
4+
export async function POST(req: NextRequest) {
5+
const privy = new PrivyClient(
6+
process.env.PRIVY_APP_ID ?? "",
7+
process.env.PRIVY_APP_SECRET ?? "",
8+
);
9+
console.log(process.env.PRIVY_APP_ID, process.env.PRIVY_APP_SECRET);
10+
console.log({ privy });
11+
const { address } = await req.json();
12+
console.log("address", address);
13+
14+
if (!address) {
15+
console.log("Missing required fields");
16+
return NextResponse.json(
17+
{ error: "Missing required fields" },
18+
{ status: 400 },
19+
);
20+
}
21+
22+
console.log("Creating wallet for user with email: ", address);
23+
24+
const wallet = await privy.importUser({
25+
linkedAccounts: [
26+
{
27+
type: "email",
28+
address: address,
29+
},
30+
],
31+
createEthereumWallet: true,
32+
});
33+
console.log(wallet);
34+
return NextResponse.json({ wallet }, { status: 200 });
35+
}

app/layout.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { Footer } from "@/components/global/footer";
99
import { NavMenu } from "@/components/global/nav-menu";
1010
import { siteConfig } from "@/config/site";
1111
import { config } from "@/config/wagmi";
12+
import { PrivyContextProvider } from "@/contexts/privy";
1213
import { WagmiContextProvider } from "@/contexts/wagmi";
14+
import { PrivyProvider } from "@privy-io/react-auth";
1315
import { headers } from "next/headers";
1416

1517
export const metadata: Metadata = {
@@ -51,11 +53,13 @@ export default function RootLayout({
5153
"min-h-screen bg-background font-sans antialiased flex flex-col",
5254
)}
5355
>
54-
<WagmiContextProvider initialState={initialState}>
55-
<NavMenu />
56-
<div className="flex-1">{children}</div>
57-
<Footer />
58-
</WagmiContextProvider>
56+
<PrivyContextProvider>
57+
<WagmiContextProvider initialState={initialState}>
58+
<NavMenu />
59+
<div className="flex-1">{children}</div>
60+
<Footer />
61+
</WagmiContextProvider>
62+
</PrivyContextProvider>
5963
</body>
6064
</html>
6165
);

contexts/privy.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { ReactNode } from "react";
55
import { PrivyProvider } from "@privy-io/react-auth";
6-
import { optimism } from "viem/chains";
6+
import { optimism } from "wagmi/chains";
77

88
const appId = process.env.NEXT_PUBLIC_PRIVY_APP_ID ?? '';
99

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@hypercerts-org/sdk": "2.2.0-beta.2",
2323
"@privy-io/react-auth": "^1.92.5",
2424
"@privy-io/server-auth": "1.15.0",
25-
"@privy-io/wagmi": "^0.2.12",
2625
"@radix-ui/react-aspect-ratio": "^1.0.3",
2726
"@radix-ui/react-avatar": "^1.0.4",
2827
"@radix-ui/react-checkbox": "^1.0.4",

0 commit comments

Comments
 (0)