getUnifiedBalances()
& getUnifiedBalance()
SET UP THE SDK BEFORE YOU START:
You can find the SDK setup instructions in the Overview page.
Use these functions to fetch consolidated token balances across all supported chains. This shows users their total available liquidity without needing to check each chain individually.
Note: Check out the API reference for a full list of supported tokens and chains.
Parameters
getUnifiedBalances()
Fetches the unified balance of all tokens across all chains for a user.
Typescript
// No parameters required
await sdk.getUnifiedBalances(): Promise<UserAsset[]>
getUnifiedBalance(symbol)
Fetches the unified balance of a specific token across all chains for a user.
Typescript
// Takes a token symbol parameter
await sdk.getUnifiedBalance(symbol: string): Promise<UserAsset | undefined>
Example
Here are some minimal examples of how to use the functions to fetch the unified balance of a user:
Typescript
// Get all balances across chains
const allBalances = await sdk.getUnifiedBalances();
console.log('All balances:', allBalances);
// Get balance for specific token
const usdcBalance = await sdk.getUnifiedBalance('USDC');
console.log('USDC balance:', usdcBalance);
Return Value
getUnifiedBalances()
: ReturnsPromise<UserAsset[]>
- Array ofUserAsset
class instancesgetUnifiedBalance(symbol)
: ReturnsPromise<UserAsset | undefined>
- SingleUserAsset
instance or undefined
Typescript
class UserAsset {
value: UserAssetDatum; // The actual data
get balance(): string; // Getter for balance
}
// The underlying data structure
interface UserAssetDatum {
symbol: string; // Token symbol (e.g., 'USDC', 'ETH')
balance: string; // Total balance across all chains
balanceInFiat: number; // USD value of the balance
decimals: number; // Token decimals
breakdown: { // Per-chain breakdown array
balance: string; // Balance on this specific chain
balanceInFiat: number; // USD value on this chain
chain: {
id: number; // Chain ID
logo: string; // Chain logo URL
name: string; // Chain name
};
contractAddress: `0x${string}`; // Token contract address
decimals: number; // Token decimals on this chain
isNative?: boolean; // Whether this is native token (optional)
}[];
}
Last updated on