npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

web3-avatar-react

v1.0.5

Published

React component for generating beautiful Web3 gradient avatars

Downloads

15

Readme

web3 avatar preview image

Web3 Avatar - React Component

Web3 Avatar is a lightweight React component library for generating beautiful gradient avatars from Ethereum addresses. This is the React version of the library. If you are looking for other versions like Vue or vanilla JavaScript, please check the main repository.

Inspired by Web3 Modal avatar


🖥️ Live Demo

See live demo on web3-avatar.netlify.app


✨ Features

  • 🎨 Beautiful gradient avatars generated from Ethereum addresses
  • ⚡ Lightweight and performant
  • 🔧 TypeScript support with full type definitions
  • 📦 Tree-shakeable ESM and CJS builds
  • ♿ Accessible and customizable
  • 🎯 Forward ref support
  • 🪝 React hooks friendly (useMemo for performance)

📦 Installation

npm install web3-avatar-react

or

yarn add web3-avatar-react

or

pnpm add web3-avatar-react

🚀 Quick Start

import { Avatar } from 'web3-avatar-react'

function App() {
  return (
    <Avatar
      address="0x1234567890123456789012345678901234567890"
      style={{ width: '100px', height: '100px' }}
    />
  )
}

Note: Styles are automatically injected when you use the component - no need to import a separate CSS file!


📖 API Reference

Props

The Avatar component accepts all standard HTML div attributes plus:

| Prop | Type | Required | Description | |------|------|----------|-------------| | address | string | Yes | The Web3/Ethereum address to generate the avatar from | | className | string | No | Additional CSS class name | | style | CSSProperties | No | Additional inline styles | | ref | React.Ref<HTMLDivElement> | No | Forward ref to the underlying div element |

All other HTML div attributes (onClick, onMouseEnter, data-*, aria-*, etc.) are also supported.


💡 Usage Examples

Basic Usage

import { Avatar } from 'web3-avatar-react'

function UserProfile() {
  const walletAddress = '0x1234567890123456789012345678901234567890'

  return (
    <Avatar
      address={walletAddress}
      style={{ width: '64px', height: '64px' }}
    />
  )
}

With Custom Styling

import { Avatar } from 'web3-avatar-react'

function CustomAvatar() {
  return (
    <Avatar
      address="0x1234567890123456789012345678901234567890"
      className="my-custom-avatar"
      style={{
        width: '120px',
        height: '120px',
        border: '2px solid white',
      }}
    />
  )
}

With Ref

import { useRef } from 'react'
import { Avatar } from 'web3-avatar-react'

function AvatarWithRef() {
  const avatarRef = useRef<HTMLDivElement>(null)

  const handleClick = () => {
    if (avatarRef.current) {
      console.log('Avatar dimensions:', avatarRef.current.getBoundingClientRect())
    }
  }

  return (
    <Avatar
      ref={avatarRef}
      address="0x1234567890123456789012345678901234567890"
      onClick={handleClick}
      style={{ width: '80px', height: '80px', cursor: 'pointer' }}
    />
  )
}

With Event Handlers

import { Avatar } from 'web3-avatar-react'

function InteractiveAvatar() {
  return (
    <Avatar
      address="0x1234567890123456789012345678901234567890"
      onClick={() => console.log('Avatar clicked!')}
      onMouseEnter={() => console.log('Mouse entered')}
      onMouseLeave={() => console.log('Mouse left')}
      style={{ width: '80px', height: '80px', cursor: 'pointer' }}
      aria-label="User wallet avatar"
      role="button"
      tabIndex={0}
    />
  )
}

Dynamic Address

import { useState } from 'react'
import { Avatar } from 'web3-avatar-react'

function DynamicAvatar() {
  const [address, setAddress] = useState('0x1234567890123456789012345678901234567890')

  return (
    <div>
      <Avatar
        address={address}
        style={{ width: '100px', height: '100px' }}
      />
      <input
        type="text"
        value={address}
        onChange={(e) => setAddress(e.target.value)}
        placeholder="Enter wallet address"
      />
    </div>
  )
}

In a List

import { Avatar } from 'web3-avatar-react'

function UserList() {
  const users = [
    { id: 1, name: 'Alice', address: '0x1234567890123456789012345678901234567890' },
    { id: 2, name: 'Bob', address: '0x9876543210987654321098765432109876543210' },
    { id: 3, name: 'Charlie', address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd' },
  ]

  return (
    <ul>
      {users.map((user) => (
        <li key={user.id}>
          <Avatar
            address={user.address}
            style={{ width: '48px', height: '48px' }}
            aria-label={`${user.name}'s avatar`}
          />
          <span>{user.name}</span>
        </li>
      ))}
    </ul>
  )
}

🎨 Styling

The component comes with default styles that are automatically injected when you use the component. No need to import a separate CSS file!

You can customize the avatar by:

  1. Using the style prop for inline styles
  2. Using the className prop to apply custom CSS classes
  3. Overriding CSS variables in your global styles

The component uses CSS custom properties internally that you can override if needed:

.web3-avatar {
  --color-av-1: /* generated color 1 */;
  --color-av-2: /* generated color 2 */;
  --color-av-3: /* generated color 3 */;
  --color-av-4: /* generated color 4 */;
  --color-av-5: /* generated color 5 */;
}

📦 TypeScript

The package includes full TypeScript definitions. The main types exported are:

import type { AvatarProps } from 'web3-avatar-react'

// AvatarProps extends React.HTMLAttributes<HTMLDivElement>
interface AvatarProps extends React.HTMLAttributes<HTMLDivElement> {
  address: string
  className?: string
  style?: CSSProperties
}

🧪 Testing

The component is fully tested with Vitest and React Testing Library.

To run tests:

npm test

🏗️ Build

To build the package:

npm run build

This will generate:

  • ESM build in dist/index.js (with styles injected)
  • CJS build in dist/index.cjs (with styles injected)
  • Type definitions in dist/index.d.ts

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


📄 License

Released under the MIT License.


🔗 Related Packages


⭐ Show your support

Give a ⭐️ if this project helped you!