Skip to content
LogoLogo

Get Token Metadata

token.getMetadata

Gets TIP-20 token metadata including name, symbol, logo URI, currency, decimals, and total supply.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x20c0000000000000000000000000000000000001',
})
 
.()
{
currency: 'USD',
decimals: 6,
logoURI: '',
name: 'AlphaUSD',
paused: false,
quoteToken: '0x20C0000000000000000000000000000000000000',
supplyCap: 340282366920938463463374607431768211455n,
symbol: 'AlphaUSD',
totalSupply: 202914184810805067765n,
transferPolicyId: 1n,
}

Recipes

Check Supply Headroom Before Minting

Read supplyCap and totalSupply together to confirm an issuance fits under the cap before submitting token.mintSync, since mints that would exceed the cap revert.

import {  } from 'viem/utils'
import {  } from './viem.config'
 
const  = '0x20c0000000000000000000000000000000000001'
const  = .('250000', 6)
 
const { ,  } = await ..({  })
 
if ( !==  &&  -  < )
  throw new ('issuance exceeds the supply cap')
 
await ..({
  : ,
  : '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
  ,
})

Screen a Token Before Accepting It at Checkout

Check paused, transferPolicyId, and currency before quoting a customer-selected token at checkout: a paused token or an always-reject transfer policy cannot settle the payment.

import {  } from './viem.config'
 
const  = await ..({
  : '0x20c0000000000000000000000000000000000001',
})
 
const  =
  . === 'USD' &&
  !. &&
  . !== 0n
 
.( ? `Accepting ${.}` : 'Payment method unavailable')
Accepting AlphaUSD

Return Value

type ReturnType = {
  /** Currency (e.g. "USD"). */
  currency: string
  /** Decimals of the token. */
  decimals: number
  /** Logo URI of the token. Empty string if unset or unsupported by the active Tempo hardfork. */
  logoURI: string
  /** Name of the token. */
  name: string
  /** Whether the token is paused. `undefined` for the default quote token (`0x20c0...0000`). */
  paused?: boolean
  /** Quote token. `undefined` for the default quote token (`0x20c0...0000`). */
  quoteToken?: Address
  /** Supply cap. `undefined` for the default quote token (`0x20c0...0000`). */
  supplyCap?: bigint
  /** Symbol of the token. */
  symbol: string
  /** Total supply of the token. */
  totalSupply: bigint
  /** Transfer policy ID. 0="always-reject", 1="always-allow", >2=custom policy. `undefined` for the default quote token (`0x20c0...0000`). */
  transferPolicyId?: bigint
}

Parameters

token

  • Type: Address | bigint

Token to operate on: a TIP-20 token id or a contract address. Metadata (name, symbol, decimals) declared on the Client's tokens set overrides values read from the contract.

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.