getUnifiedBalances()
SET UP THE SDK BEFORE YOU START:
- You can find the SDK setup instructions in the Quickstart page.
- We also created a tutorial to make it easier to understand how devs need to initialize the Nexus SDK in their project.
Use the getUnifiedBalances() function to fetch consolidated token balances across all supported chains in one call.
Note: Check out the API reference for a full list of supported tokens and chains.
Method signature
Typescript
async getUnifiedBalances(includeSwappableBalances?: boolean): Promise<UserAsset[]>Parameters
includeSwappableBalances(boolean, optional): Optionally include swappable balances in the response. Defaults tofalse.
Example
Here is a minimal example of how to use the getUnifiedBalances() function to fetch the unified balance of a user:
Typescript
// Get all balances across chains without including swappable balances
const allBalances = await sdk.getUnifiedBalances();
console.log('All balances:', allBalances);
// Get all balances across chains including swappable balances
const allBalancesIncludingSwappableBalances = await sdk.getUnifiedBalances(true);
console.log('All balances:', allBalancesIncludingSwappableBalances);Return Value
getUnifiedBalances(): ReturnsPromise<UserAsset[]>- Array ofUserAssetobjects.
Typescript
export type UserAsset = {
abstracted?: boolean;
balance: string;
balanceInFiat: number;
breakdown: {
balance: string;
balanceInFiat: number;
chain: {
id: number;
logo: string;
name: string;
};
contractAddress: `0x${string}`;
decimals: number;
isNative?: boolean;
universe: Universe;
}[];
decimals: number;
icon?: string;
symbol: string;
};Last updated on