Validate Fee Token
fee.validateToken
Validates that a token can be used as a Tempo fee token.
Fee tokens must be unpaused USD-denominated TIP-20 tokens.
Usage
import { } from './viem.config'
const = await ..({
: '0x20c0000000000000000000000000000000000001',
})
.('Fee token:', )
Fee token: { address: '0x20c0000000000000000000000000000000000001', id: 1n, metadata: { decimals: 6, name: 'USD Token', symbol: 'USD', currency: 'USD', paused: false, },}import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Screen a User-Entered Token Before Saving It
Catch the specific validation errors to give users actionable feedback before persisting a preference with fee.setUserToken.
import { , } from 'viem/tempo'
import { } from './viem.config'
try {
const { } = await ..({
: '0x20c0000000000000000000000000000000000001',
})
await ..({ : })
} catch () {
if ( instanceof )
.('This token is paused. Choose another stablecoin.')
else if ( instanceof )
.('Fee tokens must be USD-denominated.')
else throw
}import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Build a Fee Token Picker
Validate a list of candidate tokens and build picker options from the returned metadata, skipping candidates that cannot pay fees.
import { } from './viem.config'
const = [
'0x20c0000000000000000000000000000000000000',
'0x20c0000000000000000000000000000000000001',
] as
const : { : string; : string }[] = []
for (const of ) {
try {
const { , } = await ..({ })
.({ , : . })
} catch {
continue
}
}import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = {
/** Fee token contract address. */
address: Address
/** Fee token id. */
id: bigint
/** Fee token metadata. */
metadata: {
decimals: number
name: string
symbol: string
currency: string
paused: boolean
}
}The fee token address, id, and metadata.
Parameters
token
- Type:
Address | bigint
Token to validate: 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.
Errors
| Error | Description |
|---|---|
InvalidFeeTokenError | Thrown when the fee token cannot be resolved or read as a valid fee token. |
FeeTokenNotTip20Error | Thrown when the fee token is not a TIP-20 token. |
FeeTokenNotUsdError | Thrown when the fee token is not denominated in USD. |
FeeTokenPausedError | Thrown when the fee token is paused. |