A Next.js starter template for building on Base with Privy's authentication and wallet infrastructure. This can serve as a template for developers looking to integrate Base Account as an option in Privy.
This demo showcases the full spectrum of Base Account capabilities:
- Base Account Authentication - Using
wallet_connectwith SignInWithEthereum to authenticate - Sub Accounts Management - Create and manage app-specific wallet accounts to allow your give your users a pop-up-less experience
- Wallet Operations - Complete wallet interaction functionality including transactions and message signing
- Account Linking/Unlinking - Connect and disconnect various account types (Google, Email etc)
- Multi-Factor Authentication - Enhanced security features
The application is configured to prioritize Base Account as the primary wallet option:
<PrivyProvider
config={{
appearance: {
walletList: ['base_account'],
showWalletLoginFirst: true
},
defaultChain: base,
}}
>This configuration ensures that Base Account appears first in the account authentification flow, providing the optimal user experience for Base Account users.
The authentication component implements the "Sign in with Base" flow using Base Account's wallet signature authentication:
- Passwordless Authentication - No passwords required, uses wallet signatures
- SIWE Standard - Follows the "Sign in with Ethereum" (EIP-4361) standard
- Nonce Generation - Secure random nonce generation for each authentication
- Custom Button - Branded "Sign in with Base" imported from Base Account SDK
- Backend Verification - Anti-replay and backend verification using Viem's
verifyMessage
- Uses
wallet_connectRPC method withsignInWithEthereumcapabilities - Generates secure nonces using
window.crypto.randomUUID() - Provides complete authentication data (address, message, signature) for backend verification
- Ready for backend integration with viem's
verifyMessagefunction
Learn more: Base Account Authentication Guide
Sub Accounts allow you to create app-specific wallet accounts that provide a frictionless transaction experience:
- Get Existing Sub Accounts - Retrieve sub accounts for the current domain
- Create New Sub Accounts - Generate new sub accounts tied to your app
- Domain-Specific - Each sub account is bound to your application's domain
- Frictionless Transactions - Eliminate repeated signing prompts
- Spend Permissions Ready - Can spend from parent account balance
- Uses
wallet_getSubAccountsRPC method to fetch existing accounts - Uses
wallet_addSubAccountRPC method to create new sub accounts - Automatically switches to Base Sepolia for testing
- Displays sub account details including addresses and public keys
Learn more: Base Account Sub Accounts Guide
Spend Permissions enable trusted spenders to move assets from your Base Account without requiring additional signatures for each transaction:
- Create Spend Permissions - Grant spending daily/weekly/monthly allowances to trusted addresses
- Load Existing Permissions - View and manage current spend permissions
- Use Permissions - Execute transactions using granted permissions
- Permission Status Checking - Monitor active permissions and remaining allowances
- Secure Allowance Management - Set specific token amounts and time periods
- Uses
requestSpendPermissionto create new spending allowances - Uses
fetchPermissionsto retrieve existing permissions for an account - Uses
prepareSpendCallDatato prepare transactions using permissions - Uses
getPermissionStatusto check permission validity and remaining balances - Supports USDC token permissions with configurable allowances and periods
- Default Token: USDC on Base (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)
- Default Spender: Configurable trusted address
- Default Allowance: 1 USDC per day (customizable)
- Network: Base Mainnet (Chain ID: 8453)
Learn more: Base Account Spend Permissions Guide
Comprehensive wallet operation functionality including:
- Transaction sending and management
- Smart contract interactions
- Balance checking and transfers
Connect various account types to your Base Account:
- Social accounts integration
- Email account linking
- Additional wallet connections
Manage and disconnect linked accounts:
- Remove connected social accounts
- Unlink email addresses
- Disconnect additional wallets
Enhanced security features:
- Enable/disable MFA
- Manage authentication factors
- Security settings configuration
Make sure you have the following environment variables set:
NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_id
NEXT_PUBLIC_PRIVY_CLIENT_ID=your_privy_client_id# Clone the repository
git clone <repository-url>
cd base-account-privy
# Install dependencies
npm install
# or
pnpm install
# or
yarn install
# Run the development server
npm run dev
# or
pnpm dev
# or
yarn devOpen http://localhost:3000 to see the application.
src/
βββ app/
β βββ api/
β β βββ auth/
β β βββ nonce/
β β β βββ route.ts # Generate authentication nonces
β β βββ verify/
β β βββ route.ts # Verify SIWE signatures
β βββ page.tsx # Main application page
β βββ layout.tsx # Root layout
β βββ globals.css # Global styles and button classes
βββ components/
β βββ sections/
β β βββ authentication.tsx # Base Account authentication & SIWE
β β βββ sub-accounts.tsx # Sub accounts management
β β βββ spend-permissions.tsx # Spend permissions management
β β βββ wallet-actions.tsx # Wallet operations
β β βββ link-accounts.tsx # Account linking
β β βββ unlink-accounts.tsx # Account unlinking
β β βββ mfa.tsx # Multi-factor auth
β β βββ user-object.tsx # User information display
β βββ reusables/
β β βββ section.tsx # Reusable section component
β βββ ui/ # UI components (toasts, loaders, etc.)
βββ lib/
β βββ nonce-store.ts # In-memory nonce management
βββ providers/
β βββ providers.tsx # Privy provider configuration
The easiest way to deploy this Next.js app is to use the Vercel Platform:
- Push your code to a Git repository
- Import your project to Vercel
- Add your environment variables
- Deploy!
Check out the Next.js deployment documentation for more details.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.