Skip the Setup? If you want to skip the manual setup process, you can clone the complete repository and jump straight to exploring the code.
clone-and-run.sh
Complete Integration: This guide combines Privy for wallet management with OneBalance for
chain-abstracted functionality, providing the best experience for your users.
Prerequisites
Before you begin, make sure you have:- Node.js version 20 or higher
- We recommend using nvm to manage your Node.js versions
- pnpm package manager installed
- Privy Dashboard account for your application
- For a faster quickstart, you can use our pre-configured Privy App ID:
cmb94tjcj001xle0mdeerz9vp(recommended) - Alternatively, you can set up your own Privy application
- For a faster quickstart, you can use our pre-configured Privy App ID:
- OneBalance API Key - we’ll use the public test key for this example:
42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11
The pre-configured keys and IDs provided in this guide are strictly for learning purposes. For any
production application, you must use your own Privy App ID and OneBalance API Key.
1
Set up Node.js with nvm
If you don’t have Node.js installed or need to update, we recommend using nvm:
terminal-commands.sh
2
Create a new project
Set up a new React project using Next.js:When prompted, select the following options:
project-setup.sh
- Would you like to use TypeScript? › Yes
- Would you like to use ESLint? › Yes
- Would you like to use Tailwind CSS? › Yes
- Would you like your code inside a
src/directory? › Yes - Would you like to use App Router? (recommended) › Yes
- Would you like to use Turbopack for
next dev? › Yes - Would you like to customize the import alias (
@/*by default)? › No

3
Install dependencies
Install the required packages:Create a Alternatively, you can create the
install-deps.sh
.env file in the project root with your API keys:.env
.env file using command line:create-env.sh
4
Set up CORS handling
When working with the OneBalance API from a browser, you’ll need to handle CORS restrictions. The recommended approach is to create a server-side proxy using Next.js API routes.Create a new file at This proxy will allow your frontend to make requests to the OneBalance API without CORS issues.
src/app/api/[...path]/route.ts:route.ts
This proxy implementation ensures proper authentication and CORS handling for all API calls. Learn more about CORS handling in our documentation.
5
Create the OneBalance API client
Now that we have the CORS handling in place, let’s create a client to interact with the OneBalance API through our proxy.Create a file at
src/lib/onebalance.ts:onebalance.ts
This client implements several core OneBalance API endpoints:
- Predict Account Address - Get a smart contract account address before deployment
- Get Aggregated Balance - View multichain token balances
- Get Quote - Request a quote for token swaps or transfers
- Execute Quote - Execute a signed swap or transfer
- Check Transaction Status - Monitor transaction progress
6
Configure Privy Provider
Create a Privy provider component to wrap your application.Create a new file at
src/components/PrivyProvider.tsx:PrivyProvider.tsx
7
Update your root layout
Update your app’s layout to include the Privy provider:
layout.tsx
8
Create login page
Let’s create a simple login page that uses Privy’s login UI:When users click the login button, they’ll see Privy’s login UI with options for email login, social login, or connecting an existing wallet:
When users choose email login, they’ll receive a verification code to complete the sign-in process. Once verified, Privy will create a secure embedded wallet for them that can be used to sign OneBalance transactions.
page.tsx
When users choose email login, they’ll receive a verification code to complete the sign-in process. Once verified, Privy will create a secure embedded wallet for them that can be used to sign OneBalance transactions.
9
Create a dashboard page
Let’s create a simple dashboard page that we’ll enhance in the next section.Create a new directory and file at
src/app/dashboard/page.tsx:page.tsx
10
Run the application
Start the development server:Your app should now be running at http://localhost:3000. Open this URL in your browser to see it in action.
start-dev.sh
Understanding Smart Contract Accounts (SCAs)
When you set up OneBalance with Privy, it’s important to understand how the account structure works:-
Smart Contract Account (SCA):
- This is your actual deposit address where funds are stored
- The SCA enables gas abstraction, allowing you to pay for transactions using any token in your balance, not just the chain’s native gas token
- The SCA is controlled by signers (e.g., your Privy-managed key)
-
Privy-Managed Key:
- The key created via Privy acts as a signer for your SCA
- It allows you to authorize transactions from your SCA
- It is NOT where your funds are stored - the SCA is
-
Account Funding:
- When funding your OneBalance account, send assets to your SCA address (not the Privy EOA address)
- These funds will then appear in your aggregated balance across chains
For this quickstart guide, OneBalance sponsors the underlying network fees for some operations to
provide a smoother demonstration experience. In a production environment, fees are handled
according to the method outlined in our Fees documentation.
Important: Always send funds to your SCA address (which you’ll create in the next step), not
to the Privy EOA address.
The User Journey
With Privy integration, users can experience a seamless onboarding flow:- Simple Authentication: Users can login via email, social accounts, or connecting an existing wallet
- Embedded Wallet Creation: For users without a crypto wallet, Privy automatically creates one
- Smart Contract Account: The Privy wallet acts as a signer for the user’s OneBalance SCA
- Chain-Abstracted Transactions: Users can swap and transfer assets across chains without switching networks
Understanding the Integration
Our setup combines:-
Privy for Wallet Infrastructure:
- Social login options (email, passkey)
- Embedded wallet creation and management
- Simplified transaction signing
-
OneBalance for Chain Abstraction:
- Unified access to assets across chains
- Chain-abstracted swaps and transfers with no bridging
- Gas abstraction (pay fees with any token)
- Aggregated balances for a unified view of your assets
-
CORS Handling with Next.js API Routes:
- Server-side proxy to avoid browser CORS restrictions
- Secure API key management
- Consistent error handling