token.getBalance
Gets the token balance of an address.
Usage
import { client } from './viem.config'
const balance = await client.token.getBalance({
account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
token: '0x20c0000000000000000000000000000000000000',
})
console.log('Balance:', balance)
Balance: { amount: 10500000n, decimals: 6, formatted: '10.5' }import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})Return Type
type ReturnType = {
/** Balance in the token's base units. */
amount: bigint
/** Token decimals used to derive `formatted`. */
decimals: number
/** Balance formatted with the token's `decimals`. */
formatted: string
}The balance, both in base units (amount) and as a human-readable decimal string
(formatted, derived from the token's decimals).
Parameters
account
- Type:
Address
Account to get the balance of.
token
- Type:
string
Token to operate on: a chain-declared token name (resolving
its address and decimals), a TIP20 token id, or a token address.
decimals (optional)
- Type:
number
Token decimals for converting base units to human-readable amounts. Inferred from
the chain's tokens config, or fetched from the token contract when omitted.
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.