Privy provider setup
The Privy provider is configured inapp/providers.tsx with embedded wallet support:
app/providers.tsx
Configuration options
string
required
Your Privy application ID from the Privy Dashboard.
string
default:"users-without-wallets"
Automatically create embedded wallets for users who don’t have an external wallet connected.Options:
'users-without-wallets' | 'all-users' | 'off'array
Supported authentication methods for users.Options:
'email', 'passkey', 'wallet', 'google', 'twitter', 'discord', 'github'object
Customize the Privy modal appearance.
theme:'light'|'dark'accentColor: Hex color code for buttons and accents
Authentication flow
Privy provides hooks for managing user authentication:Login and logout
components/ConnectButton.tsx
components/ConnectButton.tsx:1.
usePrivy hook
TheusePrivy hook provides access to authentication state and methods:
boolean
Whether the user is currently authenticated.
boolean
Whether the Privy SDK has finished initializing.
function
Opens the Privy login modal.
function
Logs out the current user.
object
The authenticated user’s profile information.
Embedded wallet access
Access the user’s embedded wallet using theuseWallets hook:
lib/hooks/useEmbeddedWallet.ts
- Retrieves all connected wallets
- Prioritizes Privy embedded wallets
- Falls back to the first available wallet
- Returns
nullif no wallets are connected
Using the embedded wallet
Predicted address context
The application uses a context provider to manage OneBalance account addresses:lib/contexts/PredictedAddressContext.tsx
lib/contexts/PredictedAddressContext.tsx:1.
Using the predicted address
Transaction signing
Privy wallets use EIP-712 typed data signing for secure transaction approval:lib/utils/privySigningUtils.ts
Signing chain operations
lib/utils/privySigningUtils.ts
Signing quotes
ThesignQuote function signs all operations in a quote:
lib/utils/privySigningUtils.ts
Operations are signed sequentially to ensure proper nonce ordering and prevent race conditions.
lib/utils/privySigningUtils.ts:1.
Wallet connection flow
1
User initiates login
User clicks the login button, triggering the Privy modal.
2
Choose authentication method
User selects email, passkey, or wallet connection.
3
Embedded wallet creation
Privy automatically creates an embedded wallet if the user doesn’t have one.
4
Fetch predicted address
The application calls the OneBalance API to get the predicted account address.
5
Load balances
Fetch aggregated balances for the predicted address across all supported chains.
Integration example
Here’s a complete example combining Privy authentication with OneBalance quotes:Best practices
Check ready state
Always verify
ready is true before rendering UI or calling Privy methods.Cache addresses
Store predicted addresses in context to avoid redundant API calls.
Handle disconnection
Clear cached data when wallets disconnect or change.
Sequential signing
Sign operations sequentially to maintain proper nonce ordering.
Troubleshooting
Wallet not found
IfuseEmbeddedWallet returns null:
- Verify the user is authenticated
- Check that
createOnLoginis set to'users-without-wallets'or'all-users' - Ensure the Privy provider is properly configured
Signature failures
If signing fails:- Confirm the wallet is connected and unlocked
- Verify typed data structure matches EIP-712 format
- Check browser console for detailed error messages
Address prediction errors
If address prediction fails:- Ensure OneBalance API credentials are correct
- Verify the wallet address is valid
- Check network connectivity to the API
Next steps
API Reference
Explore the complete OneBalance API reference documentation