Environment variables
Create a.env file in your project root with the following variables:
.env
All environment variables are prefixed with
NEXT_PUBLIC_ to make them accessible in the browser. This is required for client-side API calls.Required variables
The base URL for the OneBalance API. Use
https://be.onebalance.io for production.Example: https://be.onebalance.ioYour OneBalance API key for authentication. Obtain this from the OneBalance Dashboard.Format: 64-character hexadecimal string
Your Privy application ID for wallet authentication. Get this from the Privy Dashboard.Format:
cm[a-z0-9]+API configuration
The application uses a proxy pattern to securely handle API requests. API credentials are managed inlib/constants.ts:
lib/constants.ts
API route handler
All OneBalance API calls are proxied through a Next.js API route atapp/api/[...path]/route.ts. This pattern:
- Centralizes API key management
- Adds authentication headers automatically
- Handles errors consistently
- Supports both GET and POST requests
Provider configuration
All application providers are configured inapp/providers.tsx. This includes:
app/providers.tsx
Provider hierarchy
The providers are nested in this order:Axios client configuration
The base API client is configured inlib/api.ts to use the Next.js API proxy:
lib/api.ts
The
baseURL is set to /api to route through the Next.js API handler, which adds authentication headers automatically.Obtaining API credentials
OneBalance API key
- Visit the OneBalance Dashboard
- Sign up or log in to your account
- Navigate to API Keys section
- Generate a new API key for your application
- Copy the key and add it to your
.envfile
Privy App ID
- Visit the Privy Dashboard
- Create a new application or select an existing one
- Copy your App ID from the settings page
- Add it to your
.envfile
Verify configuration
After setting up your environment variables, verify the configuration:- ✅ No authentication errors
- ✅ Privy wallet provider initializes
- ✅ API calls to OneBalance succeed
- All environment variables are set correctly
- The
.envfile is in the project root - You’ve restarted the development server after adding variables
Next steps
OneBalance API
Learn how to use the OneBalance API for chain abstraction
Privy wallet
Configure Privy for Web3 authentication