onchain-ui
Components

Token balance

Displays a token amount with optional logo, fiat value, and change.

TokenBalance formats a token amount beside its symbol. Add fiatValue and change to show the balance's value and percentage change below it.

Loading...
token-balance.tsxShow code
import { TokenBalance } from "@/components/ui/token-balance"export function TokenBalanceDemo() {  return (    <TokenBalance      amount={1.2845}      symbol="ETH"      name="Ethereum"      src="https://assets.coingecko.com/coins/images/279/large/ethereum.png"      fiatValue={4163.91}      change={2.41}    />  )}

Installation

npx shadcn add @onchain-ui/token-balance
Open in

Requirements

This component uses the shadcn tooltip. The install adds components/ui/tooltip.tsx if it is missing, or uses your existing file. Wrap your app with TooltipProvider to enable tooltips.

Usage

import { TokenBalance } from "@/components/ui/token-balance"

<TokenBalance amount={1.2845} symbol="ETH" fiatValue={4163.91} change={2.41} />

TokenBalance uses TokenLogo for the icon and TokenPrice for the fiat value. Pass logoProps or priceProps to customize them.

Examples

List

Loading...
token-balance-list.tsxShow code
import { TokenBalance } from "@/components/ui/token-balance"export function TokenBalanceList() {  return (    <div className="grid gap-4">      <TokenBalance amount={1.2845} symbol="ETH" fiatValue={4163.91} change={2.41} />      <TokenBalance amount={1842.2} symbol="USDC" fiatValue={1842.2} change={0.01} />      <TokenBalance amount={925.348} symbol="AERO" fiatValue={692.14} change={-4.16} />    </div>  )}

Compact

Loading...
token-balance-compact.tsxShow code
import { TokenBalance } from "@/components/ui/token-balance"export function TokenBalanceCompact() {  return (    <TokenBalance      amount={0.128934}      symbol="cbBTC"      name="Coinbase Wrapped BTC"      fiatValue={13248.12}      logoProps={{ size: "lg" }}      priceProps={{ compact: true, showChangeIcon: false }}    />  )}

Props

PropTypeDefaultDescription
amountnumber | string | null | undefined-Token amount
symbolstring | null-Token symbol shown after the amount
namestring | null-Token name, used for logo alt text
srcstring | null-Token image URL
addressstring | null-Token contract address, used for icon inference and as a fallback label
chainIdnumber | null-EVM chain id, used with address to infer a token icon
isNativebooleanfalseUse the chain's native-currency icon instead of the token contract icon
fiatValueTokenPriceProps["value"]-Fiat value for the balance
changenumber | null-Fiat value percentage change
showLogobooleantrueShow the token logo
showFiatValuebooleantrueShow fiat value when provided
localestringBrowser/default localeLocale passed to Intl.NumberFormat
maximumFractionDigitsnumber4Maximum fraction digits for token amount
minimumFractionDigitsnumber-Minimum fraction digits for token amount
fallbackReactNode"--"Shown when amount is missing or invalid
logoPropsPartial<TokenLogoProps>-Props passed to TokenLogo
pricePropsPartial<TokenPriceProps>-Props passed to TokenPrice
classNamestring-Applied to the root wrapper
amountClassNamestring-Applied to the amount line
fiatClassNamestring-Applied to the fiat value line

On this page