BigBlocks

Bitcoin Avatar

Hybrid avatar that resolves on-chain images for Bitcoin addresses, with deterministic sigma-avatars fallback when no image exists or resolution fails.

Installation

npx shadcn@latest add https://bigblocks-registry.vercel.app/r/bitcoin-avatar.json

Usage

import { BitcoinAvatar } from "@/components/blocks/bitcoin-avatar"
 
export default function Example() {
  return (
    <BitcoinAvatar
      address="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
      size="md"
      variant="marble"
    />
  )
}

How image resolution works

BitcoinAvatar follows a two-step priority chain:

  1. On-chain image — when you pass imageUrl, the bitcoin-image library resolves the protocol to a fetchable HTTP URL. Supported protocols include ord:// and b://. If the URL resolves and the <img> loads without error, the on-chain image is displayed.

  2. Deterministic fallback — if imageUrl is omitted, the URL is invalid, or the image fails to load at runtime, sigma-avatars generates a deterministic SVG seeded by the address prop. The same address always produces the same avatar, giving every Bitcoin address a consistent visual identity across your entire application without any server-side storage.

The ImageProtocols instance from bitcoin-image is shared as a module-level singleton with a one-hour in-memory cache, so repeated renders of the same imageUrl skip the resolution fetch entirely.

Examples

Variant Styles

All 10 deterministic styles from sigma-avatars. Each variant produces a visually distinct style seeded by the Bitcoin address.

On-chain image with fallback

{/* Resolves the ord:// URL and displays the on-chain image */}
<BitcoinAvatar
  address="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
  imageUrl="ord://d4d03c2e7bf8ac27f1a6b6e0e92c6a33cfe90afee8a8deb12e076172f5705894_0"
  size="lg"
/>
 
{/* Invalid URL: silently falls back to deterministic avatar */}
<BitcoinAvatar
  address="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
  imageUrl="ord://invalid-txid"
  size="lg"
/>

Using the hook directly

Use useBitcoinAvatar when you need to build a custom avatar UI or integrate resolution state into a larger component:

import { useBitcoinAvatar } from "@/components/blocks/bitcoin-avatar"
 
export function CustomAvatar({ address, imageUrl }: { address: string; imageUrl?: string }) {
  const { resolvedUrl, showOnChainImage, resolutionFailed, markResolutionFailed } =
    useBitcoinAvatar({ address, imageUrl })
 
  if (showOnChainImage && resolvedUrl) {
    return (
      <img
        src={resolvedUrl}
        alt={`Avatar for ${address.slice(0, 8)}...`}
        className="rounded-full"
        onError={markResolutionFailed}
      />
    )
  }
 
  // render your own fallback
  return <span>{address.slice(0, 4)}</span>
}

API Reference

BitcoinAvatar

PropTypeDefaultDescription
addressstringBitcoin address or BAP ID. Used as the deterministic seed for the fallback avatar. Required.
imageUrlstringOn-chain image URL to resolve (ord:// or b://). Falls back to deterministic avatar on failure.
size"sm" | "md" | "lg" | "xl""md"Avatar size. Maps to 32px, 40px, 64px, and 96px respectively.
variantAvatarVariant"marble"Visual style for the deterministic fallback avatar. See variant list below.
classNamestringAdditional CSS class names applied to the root element.

AvatarVariant

type AvatarVariant =
  | "marble"
  | "pixel"
  | "beam"
  | "ring"
  | "sunset"
  | "bauhaus"
  | "fractal"
  | "mage"
  | "barcode"
  | "pepe"

useBitcoinAvatar

The hook that powers BitcoinAvatar. Use it when you need resolution state without the default UI.

Options

OptionTypeDescription
addressstringBitcoin address or BAP ID. Required.
imageUrlstringOn-chain image URL to resolve. Optional.

Return value

PropertyTypeDescription
resolvedUrlstring | nullThe resolved HTTP URL for the on-chain image, or null if not yet resolved or unavailable.
resolutionFailedbooleantrue when resolution was attempted and failed.
showOnChainImagebooleanConvenience flag: true when imageUrl was provided, resolvedUrl is set, and resolutionFailed is false.
markResolutionFailed() => voidCall this on <img onError> to trigger fallback to the deterministic avatar.

BitcoinAvatarUI

The low-level presentational component. Accepts all resolved state from useBitcoinAvatar as explicit props, making it straightforward to test in isolation or use in a server-rendered context where you supply the resolved URL yourself.

PropTypeDefaultDescription
addressstringBitcoin address or BAP ID. Required.
pxnumberPixel size for both width and height. Required.
variantAvatarVariant"marble"Visual style for the deterministic fallback.
classNamestringAdditional CSS class names.
showOnChainImagebooleanWhether to render the on-chain <img>. Required.
resolvedUrlstring | nullThe HTTP URL to use as the <img> src. Required.
onImageError() => voidCalled when the on-chain <img> fails to load. Required.