Web3 Icons

repository·main·Indexed 42 days ago

https://github.com/0xa3k5/web3icons

A comprehensive library of over 2,500 hand-curated, optimized SVG icons and React components for tokens, networks, wallets, and exchanges in the Web3 ecosystem. Includes @web3icons/core for SVG assets and @web3icons/react for tree-shakable components and dynamic runtime loading.

Tokens
96.3K
Snippets
176
Records
237
Agent score
53%

What's inside Web3 Icons

  1. Key requirements for building a Web3 token list component

    main

    A robust token list component should incorporate the following features:

    1. Dynamic Icons: Use @web3icons/react/dynamic to render icons based on incoming token data (e.g., symbol or contract address).
    2. Search & Filtering: Implement search functionality by token symbol and name, using memoization to keep filtering performant.
    3. Smart Sorting: Order tokens by popularity first, followed by balance or alphabetical order.
    4. Network Context: Include network badges to provide multi-chain context for each token.
    5. Performance: Use virtualization (e.g., react-window) for lists containing more than ~100 items to maintain smooth scrolling.
    6. Accessibility: Adhere to ARIA patterns (combobox/listbox) and keyboard navigation support.
  2. Understand Web3Icons file naming conventions

    main

    Icons are organized by type, variant, and symbol. When accessing files directly or via imports, follow these naming rules:

    Asset Types and Variants

    • Types: tokens, networks, wallets, exchanges
    • Variants: branded, mono, background

    Naming Rules by Type

    • Tokens: Ticker in uppercase (e.g., ETH, BTC, GRT).
    • Networks: kebab-case (e.g., ethereum, binance-smart-chain).
    • Wallets: kebab-case (e.g., metamask, coinbase-wallet).
    • Exchanges: kebab-case (e.g., coinbase, uniswap).

    Example File Paths

    • svgs/tokens/branded/BTC.svg
    • svgs/networks/mono/ethereum.svg
    • svgs/wallets/branded/metamask.svg
    • svgs/exchanges/mono/bybit.svg
  3. Understand the import patterns in Web3Icons examples

    main

    The example projects demonstrate two distinct ways to consume icons, which affects bundle size and performance:

    1. Static Imports (/): Uses standard static imports. This approach is tree-shakable, meaning only the icons explicitly imported are included in your final bundle.
    2. Dynamic Imports (/dynamic): Uses dynamic imports for runtime lookup, allowing for more flexible icon loading at the cost of different bundling characteristics.
  4. Use Dynamic Icon components for runtime loading

    main

    Dynamic icon components in @web3icons/react load icons at runtime based on props. They are ideal for user-driven interfaces where icons are not known at build time (e.g., displaying a user's wallet holdings or network selection).

    Warning: Dynamic components are client-only and include all icons in the bundle. For optimal bundle size, prefer individual imports (e.g., TokenBTC) when the icons are known at build time.

  5. Use mono icon variants for dark mode

    main

    Branded token icons often suffer from low contrast, disappearing outlines, or harsh white spots when placed on dark backgrounds. The recommended solution is to use mono (single-color) icon variants in dark mode.

    Mono icons strip away brand colors and render the token's distinctive shape in a single color. This ensures consistent contrast, adapts to any background, and maintains recognition through shape.

    With @web3icons/react, you can switch between branded and mono variants using the variant prop.

    import { TokenBTC, TokenETH, TokenSOL } from '@web3icons/react'
    
    // In light mode: full brand colors
    <TokenBTC size={24} variant="branded" />
    <TokenETH size={24} variant="branded" />
    <TokenSOL size={24} variant="branded" />
    
    // In dark mode: clean, consistent mono icons
    <TokenBTC size={24} variant="mono" />
    <TokenETH size={24} variant="mono" />
    <TokenSOL size={24} variant="mono" />
  6. How tree-shaking works in @web3icons/react

    main

    To optimize your bundle size, you should use Individual Icon Components imported from the main entry point. These are tree-shakable, meaning only the icons you explicitly import will be included in your final bundle.

    Warning: Dynamic components (like <TokenIcon />) are NOT tree-shakable. They load icons on-demand at runtime using dynamic imports, which can increase bundle size and are not compatible with Server Components.

    // ✅ Static components (server-safe, tree-shakable)
    import { TokenBTC, NetworkEthereum } from '@web3icons/react'
    
    // ❌ Dynamic components (client-side only, NOT tree-shakable)
    import { TokenIcon, NetworkIcon } from '@web3icons/react/dynamic'
  7. Why use SVG instead of PNG for crypto icons

    main

    For cryptocurrency applications, SVG is superior to PNG for several reasons:

    • File Size: Optimized SVGs are significantly smaller (avg ~2.1 KB) compared to standard PNGs (avg ~8.4 KB) or retina PNGs (avg ~18.7 KB).
    • Scalability: SVGs are vector-based and render perfectly at any size (from 16px to 1600px+), whereas PNGs become blurry when scaled up.
    • Dark Mode & Styling: SVGs are part of the DOM and can be styled directly with CSS. You can change colors dynamically using the color prop or CSS color property, which is not possible with flat PNG raster images.
    • Performance: SVGs can be inlined directly into your JSX/HTML, eliminating extra HTTP requests. web3icons React components use this approach.
    • Accessibility: SVGs allow for rich accessibility via <title>, <desc>, aria-label, and role attributes.
  8. Icon Variants and Metadata

    main

    Icons in Web3 Icons support up to three variants:

    • branded: Official brand colors (Recommended)
    • mono: Single color, inherits currentColor (Recommended)
    • background: Icon with a background (Required for some types)

    Metadata Types

    Metadata is stored in JSON files. Key fields include:

    • Tokens: id, filePath, symbol, name, marketCapRank, addresses (map of network to address), and variants.
    • Networks: id, filePath, chainId, caip2id, name, shortName, nativeCoinId, and variants.
    • Wallets: id, filePath, name, and variants.
    • Exchanges: id, filePath, name, type (e.g., dex), and variants.

    Sharing Icons via filePath

    You can reuse an existing icon for a new metadata entry by referencing its filePath. For example, a wrapped token can reference a base token's icon:

    {
      "id": "wrapped-bitcoin",
      "filePath": "token:BTC",
      "symbol": "WBTC",
      "name": "Wrapped Bitcoin"
    }
  9. Optimize bundle size with tree-shaking

    main

    To minimize bundle size, use individual static imports for icons. This allows your bundler to tree-shake unused icons, resulting in a bundle impact of approximately 1-2KB gzipped per icon.

    Avoid dynamic lookups from a central Icons object (e.g., Icons[iconName]), as this prevents tree-shaking and forces the inclusion of all icons in your bundle (~2MB+ gzipped).

    // Good - only BTC and ETH icons included
    import { TokenBTC, TokenETH } from '@web3icons/react';
    
    // Bad - includes ALL icons
    import { Icons } from '@web3icons/react';
    const iconName = 'TokenETH';
    const Icon = Icons[iconName]; // Dynamic lookup prevents tree-shaking
  10. Access icons via SvgCollections object keys

    main

    Icons within SvgCollections are accessed using specific key patterns based on their type. Use these patterns to construct keys for dynamic lookups.

    Key Patterns

    • Tokens: {variant}{SYMBOL} (e.g., brandedBTC, monoETH)
    • Networks: {variant}{PascalCase} (e.g., brandedEthereum, monoPolygon)
    • Wallets: {variant}{PascalCase} (e.g., brandedMetamask, monoRainbow)
    • Exchanges: {variant}{PascalCase} (e.g., brandedUniswap, monoBinance)

    Available Variants

    • branded: Official brand colors (Available for all types)
    • mono: Monochromatic, single color (Available for all types)
    • background: Circular background (Available for tokens only)