Skip to content
LogoLogo

Get Token Total Supply

token.getTotalSupply

Gets the total supply of a TIP-20 token.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x20c0000000000000000000000000000000000000',
})
 
.('Total Supply:', )
Total Supply: { amount: 1000000000000000n, decimals: 6, formatted: '1000000000' }

Recipes

Snapshot Supply for a Reserve Attestation

Resolve the snapshot block with block.getNumber, then pass blockNumber so the reported circulating supply matches custodian reserve balances captured at the same moment.

import {  } from './viem.config'
 
const  = await ..()
 
const  = await ..({
  ,
  : '0x20c0000000000000000000000000000000000001',
})
 
.(`Supply at block ${}:`, .)
Supply at block 19868020: 48250000.5

Return Value

type ReturnType = {
  /** Total supply in the token's base units. */
  amount: bigint
  /** Token decimals used to derive `formatted`. */
  decimals: number
  /** Total supply formatted as a human-readable decimal string. */
  formatted: string
}

The total supply, both in base units (amount) and as a human-readable decimal string (formatted, derived from the token's decimals).

Parameters

decimals

  • Type: number

Decimals used to convert between base units and the human-readable amount. Inferred from the Client's tokens set when token matches a declared token; otherwise fetched from the token contract when needed.

token

  • Type: Address | bigint

Token to operate on: 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.