Deterministic avatar generator for Ethereum addresses using layered NFT artwork
Avatario generates unique, deterministic avatars for Ethereum addresses by compositing multiple image layers. Each address always produces the same avatar, making it perfect for consistent user representation across Web3 applications.
Originally created for baes.app to display Bario Punks-inspired avatars for users without ENS or Basename profile pictures.
- Deterministic Generation - Same address = same avatar, always
- Layer-based Composition - Combine multiple image layers for rich artwork
- Multiple Sizes - Support for 16px to 2048px output
- Pixelated Rendering - Crisp pixel art aesthetic
- Smart Caching - In-memory LRU cache for performance
- Domain Protection - Configurable domain whitelist
- Vercel Ready - Optimized for Vercel deployment
GET /api/avatar/[address]?size=[size]
address(required) - Valid Ethereum address (0x...)size(optional) - Avatar size in pixels (16-2048, default: 512)
# Generate 512px avatar
curl https://avatario.baes.so/api/avatar/0x742d35Cc6634C0532925a3b844Bc9e7595f0fEb1
# Generate 256px avatar
curl https://avatario.baes.so/api/avatar/0x742d35Cc6634C0532925a3b844Bc9e7595f0fEb1?size=256Returns a PNG image with the following headers:
Content-Type: image/pngCache-Control: public, max-age=31536000, immutableX-Cache: HIT|MISS(cache status)
- Node.js 18+
- npm or yarn
-
Clone the repository
git clone https://github.com/panikadak/avatario.git cd avatario -
Install dependencies
npm install
-
Add your artwork layers
Create your layer folders in
public/layers/:public/layers/ ├── 01-Background/ │ ├── bg1.png │ ├── bg2.png │ └── ... ├── 02-Character/ │ ├── char1.png │ ├── char2.png │ └── ... └── 03-Accessories/ ├── acc1.png ├── acc2.png └── ... -
Update layer configuration
Edit
app/types/index.ts:export const LAYER_FOLDERS = [ '01-Background', '02-Character', '03-Accessories' ] as const;
-
Configure allowed domains (optional)
Edit
app/lib/domain-validator.ts:const PRODUCTION_DOMAINS = [ 'yourdomain.com', 'yourapp.io' ];
-
Run development server
npm run dev
-
Test your API
Visit
http://localhost:3000and test with an Ethereum address!
- Prepare your layers: Ensure all images are the same size (recommended: 1000x1000px)
- Organize in folders: Name folders with prefixes (01-, 02-, etc.) to control layer order
- Update configuration: Modify
LAYER_FOLDERSinapp/types/index.ts - Customize selection logic: Edit
app/lib/avatar-generator.tsif needed
- Format: PNG with transparency support
- Size: All images should be the same dimensions
- Naming: Use consistent naming (numbers, descriptive names, etc.)
Avatar sizes (app/types/index.ts):
export const DEFAULT_AVATAR_SIZE = 512;
export const MIN_AVATAR_SIZE = 16;
export const MAX_AVATAR_SIZE = 2048;Cache settings (app/lib/avatar-cache.ts):
// Cache up to 200 avatars for 24 hours
const avatarCache = new AvatarCache(200, 24);Domain whitelist (app/lib/domain-validator.ts):
const PRODUCTION_DOMAINS = [
'yourdomain.com'
];- Connect your repository to Vercel
- Configure environment: No additional environment variables needed
- Deploy: Vercel will automatically build and deploy
Ensure your platform supports:
- Node.js 18+
- Canvas library (for image processing)
- Static file serving from
public/
Avatario uses a deterministic algorithm to ensure consistency:
- Address Processing: Ethereum address is normalized and converted to a numeric seed
- Layer Selection: Each layer folder gets a pseudo-random selection based on the seed
- Image Composition: Selected images are layered using Canvas API
- Pixelated Rendering: Image smoothing is disabled for crisp pixel art output
- Caching: Generated avatars are cached in memory and at CDN level
app/
├── api/avatar/[address]/ # API endpoint
├── lib/
│ ├── avatar-cache.ts # LRU cache implementation
│ ├── avatar-generator.ts # Layer selection logic
│ ├── domain-validator.ts # Security & domain checking
│ ├── ethereum-utils.ts # Address validation & processing
│ └── image-processor.ts # Canvas-based image composition
├── types/index.ts # TypeScript definitions
└── page.tsx # Demo interface
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details.
Created by Bario Entertainment System
- Website: baes.so
- Sufficiently Decentralized Video Game Marketplace: baes.app
- Twitter: @basebario
Need help or want to use this for your project? Reach out to us at @basebario on Twitter!