Skip to main content
Portfolio tracking provides a unified view of your token holdings across multiple blockchains. Instead of checking each network separately, you see all your balances aggregated in a single interface.

How it works

OneBalance aggregates your balances by:
  1. Querying your account address across all supported chains
  2. Identifying tokens you hold on each chain
  3. Combining balances for the same token across different chains
  4. Converting values to USD for easy comparison
  5. Calculating your total portfolio value
This gives you a complete picture of your holdings without switching networks or checking multiple wallets.

Implementation

Fetching balances

Balances are fetched using the useBalances hook:
lib/hooks/useBalances.ts

API integration

The balances API endpoint returns aggregated data:
lib/api/balances.ts

Balance types

The balance response includes detailed type information:
lib/types/balances.ts

Displaying balances

Total portfolio value

Show the total value of all holdings:
components/BalanceDisplay.tsx

Per-asset balances

Display individual token balances with proper decimal formatting:

Balance updates

Balances automatically refresh after transactions:
components/SwapForm.tsx

Token input integration

The swap and transfer forms integrate balance display:
components/TokenInput.tsx

Balance-based validation

The application validates amounts against available balances:
components/SwapForm.tsx

Real-time balance tracking

Balances are tracked dynamically as the user interacts with the application:
components/SwapForm.tsx

Aggregated asset IDs

Assets are identified using aggregated IDs that represent the token across all chains:

Loading states

Handle loading states gracefully:

Error handling

Display clear error messages when balance fetching fails:

USD value conversion

Balances include USD values for easy portfolio tracking:

Percentage-based operations

Users can quickly select a percentage of their balance:
components/SwapForm.tsx
Common percentages: 25%, 50%, 75%, 100%

Best practices

1

Fetch on wallet connection

Load balances immediately when the user connects their wallet to provide instant feedback.
2

Refresh after transactions

Always refresh balances after successful swaps or transfers to show updated values.
3

Handle loading states

Show skeleton loaders while balances are being fetched to improve perceived performance.
4

Cache balance data

Store balance data in state to avoid unnecessary API calls when switching between views.
5

Format amounts properly

Always account for token decimals when displaying or parsing amounts.
Balances are aggregated across all chains, but individual chain balances can be queried separately if needed for advanced use cases.

API reference

For more details on balance-related endpoints: