token.getAllowance
Gets the amount of tokens that a spender is approved to transfer on behalf of an account.
Usage
import { client } from './viem.config'
const allowance = await client.token.getAllowance({
account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
spender: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
token: '0x20c0000000000000000000000000000000000000',
})
console.log('Allowance:', allowance)
Allowance: { 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 = {
/** Allowance in the token's base units. */
amount: bigint
/** Token decimals used to derive `formatted`. */
decimals: number
/** Allowance formatted with the token's `decimals`. */
formatted: string
}The remaining allowance, both in base units (amount) and as a human-readable
decimal string (formatted, derived from the token's decimals).
Parameters
account
- Type:
Address
Account that owns the tokens.
spender
- Type:
Address
Account allowed to spend the account's tokens.
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.