Exports
Functions
getBalance(chainId, tokenAddress, walletAddress, cache?)
Get token balance for a specific wallet address.| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | number | Yes | Chain ID |
tokenAddress | string | Yes | Token contract address |
walletAddress | string | Yes | Wallet address to check |
cache | BalanceCache | No | Optional cache instance |
Balance
| Property | Type | Description |
|---|---|---|
token | Token | Token metadata |
balance | string | Balance in smallest unit |
formatted | string | Balance formatted with decimals |
balanceUsd | number | undefined | Balance in USD |
InvalidAddressErrorif the wallet address is invalidBalanceFetchErrorif the API fails and no cache available
getBalances(walletAddress, chainIds, tokenAddresses?, cache?)
Get token balances across multiple chains in parallel.| Parameter | Type | Required | Description |
|---|---|---|---|
walletAddress | string | Yes | Wallet address to check |
chainIds | number[] | Yes | Array of chain IDs |
tokenAddresses | Record<number, string[]> | No | Token addresses per chain |
cache | BalanceCache | No | Optional cache instance |
BalancesResponse
| Property | Type | Description |
|---|---|---|
balances | Record<number, Balance[]> | Balances grouped by chain ID |
totalUsd | number | Total value in USD |
isStale | boolean | Whether any data is from stale cache |
getChainBalances(walletAddress, chainId, cache?)
Get all supported token balances for a specific chain.| Parameter | Type | Required | Description |
|---|---|---|---|
walletAddress | string | Yes | Wallet address to check |
chainId | number | Yes | Chain ID |
cache | BalanceCache | No | Optional cache instance |
BalanceWithMetadata with extended information.
Example:
getBalanceWithMetadata(chainId, tokenAddress, walletAddress, cache?)
Get balance with additional metadata like USD value and price.BalanceWithMetadata
| Property | Type | Description |
|---|---|---|
token | Token | Token metadata |
balance | string | Balance in smallest unit |
formatted | string | Balance formatted with decimals |
balanceUsd | number | undefined | Balance in USD |
hasBalance | boolean | Whether balance is greater than 0 |
chainId | number | Chain ID |
priceUsd | number | undefined | Current token price in USD |
validateBalance(quote, walletAddress, cache?)
Validate that a user has sufficient balance to execute a quote.| Parameter | Type | Required | Description |
|---|---|---|---|
quote | Quote | Yes | Quote to validate against |
walletAddress | string | Yes | Wallet address to check |
cache | BalanceCache | No | Optional cache instance |
BalanceValidation
| Property | Type | Description |
|---|---|---|
valid | boolean | Whether validation passed |
warnings | BalanceWarning[] | Array of warnings |
tokenBalance | Balance | Source token balance |
gasBalance | Balance | Native token balance for gas |
| Type | Description |
|---|---|
INSUFFICIENT_BALANCE | Not enough tokens to bridge |
INSUFFICIENT_GAS | Not enough native token for gas |
LOW_GAS | Gas balance is low (< 2x estimated) |
checkBalance(chainId, tokenAddress, walletAddress, amount, cache?)
Quick check if a user has sufficient balance for a specific amount.| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | number | Yes | Chain ID |
tokenAddress | string | Yes | Token address |
walletAddress | string | Yes | Wallet address |
amount | string | Yes | Amount to check (smallest unit) |
cache | BalanceCache | No | Optional cache instance |
BalanceCheckResult
| Property | Type | Description |
|---|---|---|
sufficient | boolean | Whether balance is sufficient |
balance | string | Current balance |
formatted | string | Formatted balance |
required | string | Required amount |
shortfall | string | undefined | Amount short (if insufficient) |
Error Types
BalanceFetchError
Thrown when balance fetching fails.InvalidAddressError
Thrown when an invalid wallet address is provided.BalanceCache Class
TheBalanceCache class manages caching for balance data with a 30-second TTL.
