Get DEX Balance
dex.getBalance
Gets an account's token balance held on the DEX.
Usage
import { } from './viem.config'
const = await ..({
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0x20c0000000000000000000000000000000000000',
})
.('DEX balance:', )
DEX balance: 100000000nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Reconcile Wallet and Exchange Holdings
Combine dex.getBalance with token.getBalance to report where a token's funds sit before closing the books.
import { } from './viem.config'
const = '0x20c0000000000000000000000000000000000000'
const = await ..({ : })
const = await ..({ : })
.('Total holdings:', + .)
Total holdings: 350000000nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Spot Funds Left on the Exchange
Map every token you trade through dex.getBalance to find balances worth withdrawing after a trading session.
import { } from './viem.config'
const = [
'0x20c0000000000000000000000000000000000000',
'0x20c0000000000000000000000000000000000001',
] as
const = await .(
.(async () => ({
: await ..({ }),
,
})),
)
const = .(({ }) => > 0n)import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = bigintThe user's token balance on the DEX.
Parameters
account
- Type:
Account | Address - Default:
client.account
Account that owns the DEX balance.
token
- Type:
Address | bigint
Token to query: a TIP-20 token id or a contract address.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.