getBalancesForSwap()
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 getBalancesForSwap() function to fetch token balances that can be used in swap operations 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
getBalancesForSwap(): Promise<Array<{
amount: string;
chainID: number;
decimals: number;
symbol: string;
tokenAddress: `0x${string}`;
universe: Universe;
value: number;
logo: string;
}>>Parameters
- None
Example
Here is a minimal example of how to use the getBalancesForSwap() function to fetch balances that are eligible to be used as swap inputs:
Typescript
// Get all balances that are eligible for swap operations
const swapBalances = await sdk.getBalancesForSwap();
console.log('Swap balances:', swapBalances);Return Value
getBalancesForSwap(): Returns an array of anonymous objects with the following properties:
Typescript
// Docs-only alias. Not exported by the SDK.
type SwapBalanceItem = {
amount: string;
chainID: number;
decimals: number;
symbol: string;
tokenAddress: `0x${string}`;
universe: Universe;
value: number;
logo: string;
};Last updated on