Fetch Swap Balances
Fetch token balances available for swap operations across all supported chains in one call.
You are viewing the Nexus SDK v2 docs. For the current SDK, see the v3 docs and the v2 → v3 migration guide.
Note
SET UP THE SDK BEFORE YOU START:Install and initialize the client first — see Installation and SDK Setup.
getBalancesForSwap() function to fetch token balances that can be used in swap operations across all supported chains in one call.
Method signature
getBalancesForSwap(): Promise<TokenBalance[]>Note
getBalancesForSwap() returns the same TokenBalance[] shape as getBalancesForBridge(). If you need the tokens that can be used for bridging instead, use getBalancesForBridge().Parameters
- None
Example
getBalancesForSwap() function to fetch balances that are eligible to be used as swap inputs:
// Get all balances that are eligible for swap operations
const swapBalances = await client.getBalancesForSwap();
console.log('Swap balances:', swapBalances);Return Value
getBalancesForSwap() returns Promise<TokenBalance[]> — an array of TokenBalance objects. Each TokenBalance aggregates a token's holdings across every chain it lives on, with the per-chain split in chainBalances.
export type TokenBalance = {
balance: string; // Aggregate balance across all chains (human-readable)
value: string; // Aggregate fiat value (string for precision)
chainBalances: ChainBalance[];// Per-chain breakdown
currencyId?: number; // Currency identifier (when applicable)
decimals: number;
logo: string;
name: string; // Display label (e.g. "USDC/USDM")
symbol: string; // Majority symbol by chain count
};
export type ChainBalance = {
balance: string; // Balance on this chain (human-readable)
value: string; // Fiat value on this chain (string for precision)
symbol: string;
chain: {
id: number;
logo: string;
name: string;
};
contractAddress: `0x${string}`;
decimals: number;
universe: Universe; // VM family of the chain (e.g. 'EVM')
};Note
Field renames from v1:
balanceInFiat → value, icon → logo, and breakdown → chainBalances. See the full type definitions on GitHub.How is this guide?