Prerequisites
Before you begin, ensure you have:- Node.js 18+ installed
- pnpm package manager (or npm/yarn)
- A OneBalance API key (get one here)
- A Privy account for Web3 authentication (sign up here)
Installation
Install dependencies
Install all required packages using pnpm (or your preferred package manager):The application uses these key dependencies:
- Next.js 15 with App Router and Turbopack
- Privy for Web3 authentication and embedded wallets
- Wagmi & Viem for Ethereum interactions
- Tailwind CSS with shadcn/ui components
- TanStack Query for data fetching and caching
Configure environment variables
Create a
.env file in the root directory with your API credentials:.env
The example
.env.example file includes demo credentials. For production use, replace these with your own API keys from OneBalance and Privy.Your first swap
Once the application is running, follow these steps to execute your first chain-abstracted token swap:Connect your wallet
Click Login in the top-right corner. You can:
- Sign in with email (no wallet needed)
- Use a passkey for passwordless login
- Connect an existing Web3 wallet
Select tokens
On the Swap page:
- Choose the token you want to sell (e.g., USDC)
- Choose the token you want to buy (e.g., ETH)
Enter amount
Type the amount you want to swap, or click the percentage buttons (25%, 50%, 75%, 100%) to quickly select a portion of your balance.The app will automatically:
- Fetch a real-time quote from OneBalance
- Show the exchange rate and estimated output
- Display any applicable fees
Review the quote
Check the quote details:
- Exchange rate: Current rate between the two tokens
- Estimated output: How much you’ll receive
- Expiration: Quotes are valid for 30 seconds
Execute the swap
Click Swap to execute the transaction. OneBalance will:
- Route your tokens across the optimal chains
- Handle all cross-chain bridging automatically
- Execute the swap at the best available rate
- Deliver tokens to your wallet
Available scripts
The project includes several useful scripts defined inpackage.json:
Project structure
Here’s an overview of the key directories:Next steps
Core Features
Explore all 8 key features of the application
API Integration
Learn how OneBalance API powers chain abstraction
Authentication
Understand Privy’s embedded wallet system
Customization
Customize the UI to match your brand