Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Koniverse/SubWallet-Extension/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheBalanceService is responsible for tracking and managing token balances across different blockchain networks supported by SubWallet Extension. It provides real-time balance updates, token detection, and cross-chain transfer capabilities.
Key Features
- Multi-chain balance tracking (Substrate, EVM, Ton, Cardano, Bitcoin)
- Real-time balance subscriptions
- Automatic token detection and enabling
- Transfer balance calculations
- XCM (Cross-Consensus Message) support
- Token optimization and balance caching
Class: BalanceService
Constructor
The global state object of the extension
Properties
Indicates whether the service is currently running
Current status of the service (NOT_INITIALIZED, INITIALIZING, INITIALIZED, STARTING, STARTED, STOPPING, STOPPED)
Core Methods
init()
Initializes the balance service and loads cached data.start()
Starts the balance service and begins tracking balances.stop()
Stops the balance service and unsubscribes from all balance updates.Balance Subscription Methods
subscribeBalance()
Subscribes to balance updates for a specific address, chain, and token.The wallet address to track
The chain slug (e.g., ‘polkadot’, ‘kusama’, ‘ethereum’)
The token identifier. If undefined, uses the native token
Type of balance to track (TRANSFERABLE, TOTAL, TOTAL_MINUS_RESERVED)
Optional extrinsic type for context-specific balance calculations
Optional callback function called on balance updates
Unsubscribe function to stop receiving updates
Current balance data
getTransferableBalance()
Fetches the transferable balance for an address on a specific chain.getTotalBalance()
Fetches the total balance (free + locked) for an address.subscribeBalanceMap()
Subscribes to the complete balance map for all accounts and tokens.Observable that emits balance updates for all tracked tokens
Token Detection Methods
autoEnableChains()
Automatically detects and enables chains with non-zero balances.Array of addresses to check for balances
evmDetectBalanceToken()
Detects EVM tokens with balances for given addresses.Array of token slugs with non-zero balances
substrateDetectBalanceToken()
Detects Substrate tokens with balances for given addresses.Transfer Methods
getOptimalTransferProcess()
Determines the optimal transfer path for cross-chain transfers.getTokensHasBalance()
Retrieves tokens with non-zero balances for a specific address and chain.Map of token slugs to balance items
Utility Methods
reloadBalance()
Reloads all balance data from scratch.removeBalanceByAddresses()
Removes balance data for specific addresses.Array of addresses to remove
optimizeEnableTokens()
Optimizes the token list by enabling tokens with balances and disabling zero-balance tokens.Types
BalanceType
BalanceItem
Events
The BalanceService listens to and emits events through the EventService:account.updateCurrent- Current account changedaccount.add- New account addedaccount.remove- Account removedchain.updateState- Chain state changedasset.updateState- Asset state changed