Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Step-by-step guide to integrating Phantom Connect in a Next.js App Router application.
npm install @phantom/react-sdk @solana/web3.js
// app/providers.tsx "use client"; import { PhantomProvider, darkTheme } from "@phantom/react-sdk"; import { AddressType } from "@phantom/browser-sdk"; export function Providers({ children }: { children: React.ReactNode }) { return ( <PhantomProvider config={{ providers: ["google", "apple", "injected"], appId: "your-app-id", // Get from phantom.com/portal addressTypes: [AddressType.solana], authOptions: { redirectUrl: "https://yourapp.com/auth/callback", }, }} theme={darkTheme} appName="Your App" > {children} </PhantomProvider> ); }
// app/layout.tsx import { Providers } from "./providers"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> <Providers>{children}</Providers> </body> </html> ); }
// app/auth/callback/page.tsx "use client"; import { ConnectBox } from "@phantom/react-sdk"; export default function AuthCallback() { return ( <div style={{ display: "flex", justifyContent: "center", alignItems: "center", minHeight: "100vh" }}> <ConnectBox /> </div> ); }
// app/page.tsx "use client"; import { useModal, usePhantom, useAccounts, useDisconnect, useSolana } from "@phantom/react-sdk"; export default function Home() { const { open } = useModal(); const { isConnected, isLoading } = usePhantom(); const addresses = useAccounts(); const { disconnect } = useDisconnect(); const { solana } = useSolana(); if (isLoading) return <p>Loading...</p>; if (isConnected && addresses) { return ( <main> <p>Connected: {addresses[0]?.address}</p> <button onClick={() => solana.signMessage("Hello!")}>Sign Message</button> <button onClick={() => disconnect()}>Disconnect</button> </main> ); } return ( <main> <h1>Welcome</h1> <button onClick={open}>Connect Wallet</button> </main> ); }
https://yourapp.com/auth/callback
Was this page helpful?