Address display
Displays an EVM wallet address with copy-to-clipboard and an optional block explorer link.
AddressDisplay truncates a wallet address and adds buttons to copy it or open its block explorer page.
address-display.tsxShow code
import { AddressDisplay } from "@/components/ui/address-display"export function AddressDisplayDemo() { return ( <AddressDisplay address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" /> )}Installation
npx shadcn add @onchain-ui/address-displayRequirements
Add <Toaster /> to your root layout to show a toast when someone copies an address. The install includes @onchain-ui/sonner, which uses your app's CSS tokens and does not depend on next-themes. If you already have components/ui/sonner.tsx, the install uses that file.
import { Toaster } from "@/components/ui/sonner"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Toaster />
</body>
</html>
)
}Dependencies
The registry item uses viem, sonner, and lucide-react by default.
npm install viem sonner lucide-reactPass copyIcon and explorerIcon to use another icon set.
import { Copy01Icon, LinkSquare02Icon } from "@hugeicons/core-free-icons"
import { HugeiconsIcon } from "@hugeicons/react"
import { AddressDisplay } from "@/components/ui/address-display"
<AddressDisplay
address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
copyIcon={<HugeiconsIcon icon={Copy01Icon} className="size-3 shrink-0" />}
explorerIcon={
<HugeiconsIcon icon={LinkSquare02Icon} className="size-3 shrink-0" />
}
/>Usage
import { AddressDisplay } from "@/components/ui/address-display"
<AddressDisplay address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />Pass chainId to select a block explorer. Built-in chains include Ethereum with ID 1, Optimism with 10, Polygon with 137, Base with 8453, and Arbitrum with 42161. Without a chainId, explorer links point to Etherscan.
AddressDisplay also reads explorer URLs from the viem chains in Configuration. Add a chain there or reuse your wagmi chain list to make its explorer available.
Pass a full explorerUrl to override the link for one address. If the component cannot find the supplied chainId and you have not set explorerUrl, it hides the link. This avoids linking to activity on the wrong chain.
Examples
With Base explorer
Pass chainId to link to a known chain's explorer, or explorerUrl for any other chain.
address-display-base.tsxShow code
import { AddressDisplay } from "@/components/ui/address-display"export function AddressDisplayWithExplorer() { return ( <AddressDisplay address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" chainId={8453} /> )}Full address
Disable truncation to show the full address. Full addresses can wrap in narrow containers, so prefer the default truncated display in dense layouts.
address-display-full.tsxShow code
import { AddressDisplay } from "@/components/ui/address-display"export function AddressDisplayFull() { return ( <AddressDisplay address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" truncate={false} showExplorer={false} /> )}Copy only
Hide the explorer link when you just need clipboard copy.
address-display-copy-only.tsxShow code
import { AddressDisplay } from "@/components/ui/address-display"export function AddressDisplayCopyOnly() { return ( <AddressDisplay address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" showExplorer={false} /> )}Props
| Prop | Type | Default | Description |
|---|---|---|---|
address | Address | - | Required EVM wallet address |
label | ReactNode | Truncated address | Display label. The copied value is always the underlying address |
truncate | boolean | true | Truncate the address |
truncateChars | number | 4 | Characters shown at each end when truncated |
showCopy | boolean | true | Show copy-to-clipboard button |
showExplorer | boolean | true | Show block explorer link |
chainId | number | null | 1 | EVM chain id used to pick a known block explorer. An unrecognised id omits the link |
explorerUrl | string | Derived from chainId | Full explorer URL override for this address |
copyIcon | ReactNode | Lucide copy icon | Icon rendered before the address when copy is enabled |
explorerIcon | ReactNode | Lucide external link icon | Icon rendered for the explorer link |
className | string | - | Applied to the root wrapper |
addressClassName | string | - | Applied to the address text or copy trigger |