Examples
Complete examples and integration patterns for B3 Global Accounts
Warning
B3 Global Accounts are deprecated. Upside and AnySpend now sign in with your own wallet. If you held funds in a Global Account and need help, ask in the B3 Discord. The team never DMs first and will never ask for your seed phrase or private key.
E-commerce Application Example
Example showing B3 Global Accounts integration in an e-commerce context.
tsximport { B3Provider, SignInWithB3, useAccountAssets, useAccountWallet} from "@b3dotfun/sdk/global-account/react";const baseChain = { id: 8453, name: "Base", nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, rpc: "YOUR_BASE_RPC_URL",};function EcommerceApp() { return ( <B3Provider theme="light" environment="production" partnerId="your-awesome-partner-id"> <ShopContainer /> </B3Provider> );}function ShopContainer() { const { address } = useAccountWallet(); return ( <div className="shop-container"> <header className="shop-header"> <h1>🛍️ B3 NFT Marketplace</h1> </header> <main> {address ? ( <AuthenticatedShop address={address} /> ) : ( <GuestShop /> )} </main> </div> );}function AuthenticatedShop({ address }: { address: string }) { const { data } = useAccountAssets(address); return ( <div className="authenticated-shop"> <section className="user-collection"> <h2>Your Collection</h2> <div className="asset-grid"> {data?.nftResponse.nfts?.map((nft) => ( <div key={nft.nft_id} className="asset-card"> <img src={nft.image_url} alt={nft.name} /> <h3>{nft.name}</h3> </div> ))} </div> </section> <section className="marketplace"> <h2>Marketplace</h2> <MarketplaceGrid /> </section> </div> );}function GuestShop() { return ( <div className="guest-shop"> <section className="hero"> <h2>Discover Amazing NFTs</h2> <p>Sign in to start collecting and trading</p> <SignInWithB3 strategies={["google"]} chain={baseChain} partnerId="nft-marketplace" onLoginSuccess={() => { console.log("User joined the marketplace!"); }} /> </section> <section className="featured"> <h2>Featured Collections</h2> <MarketplaceGrid /> </section> </div> );}function MarketplaceGrid() { // Mock marketplace items const items = [ { id: 1, name: "Cool NFT #1", price: "0.1 ETH", image: "/nft1.jpg" }, { id: 2, name: "Rare Item #42", price: "0.5 ETH", image: "/nft2.jpg" }, // ... more items ]; return ( <div className="marketplace-grid"> {items.map((item) => ( <div key={item.id} className="marketplace-item"> <img src={item.image} alt={item.name} /> <h3>{item.name}</h3> <p className="price">{item.price}</p> <button className="buy-btn">Buy Now</button> </div> ))} </div> );}export default EcommerceApp;
Next.js App Router Example
Example for Next.js 13+ App Router.
tsx// app/layout.tsximport { B3Provider } from '@b3dotfun/sdk/global-account/react';import '@b3dotfun/sdk/index.css';export default function RootLayout({ children,}: { children: React.ReactNode;}) { return ( <html lang="en"> <body> <B3Provider theme="light" environment="production" partnerId="your-awesome-partner-id"> {children} </B3Provider> </body> </html> );}// app/page.tsx'use client';import { useAccountWallet } from '@b3dotfun/sdk/global-account/react';import AuthComponent from './components/AuthComponent';import Dashboard from './components/Dashboard';export default function HomePage() { const { address } = useAccountWallet(); return ( <main> {address ? <Dashboard /> : <AuthComponent />} </main> );}// app/components/AuthComponent.tsx'use client';import { SignInWithB3 } from '@b3dotfun/sdk/global-account/react';const baseChain = { id: 8453, name: "Base", nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, rpc: "YOUR_BASE_RPC_URL",};export default function AuthComponent() { return ( <div className="auth-container"> <h1>Welcome to B3 App</h1> <SignInWithB3 strategies={["google"]} chain={baseChain} partnerId="nextjs-app" onLoginSuccess={(account) => { console.log("Next.js auth success:", account); }} /> </div> );}
CSS Styling Examples
Example CSS for styling B3 components:
css/* Custom B3 component styles */.b3-auth-container { max-width: 400px; margin: 0 auto; padding: 2rem; border-radius: 12px; background: linear-gradient(135deg, #007AFF 0%, #4DA6FF 100%); color: white;}.b3-sign-in-button { width: 100%; padding: 12px 24px; border: none; border-radius: 8px; background: rgba(255, 255, 255, 0.2); color: white; font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s ease;}.b3-sign-in-button:hover { background: rgba(255, 255, 255, 0.3); transform: translateY(-2px);}