blo is a small and fast library to generate Ethereum identicons.
Features
- 🐥 Small: 0.67 KB gzipped.
- 💥 Fast: 3.5x faster than the second fastest solution.
- 🔍 Optimized: Leverages SVG to generate compact and sharp images at any size.
- 💆 Simple: Focuses on Ethereum identicons only, allowing for a simpler API.
- 🗂 Typed: Ships with types included.
- 👫 Works everywhere: browsers, Bun, Node.js.
- ☁️ Zero dependencies.
Library Comparison
Library | Renders/sec1 | Size | Types | Environment2 | Rendering |
---|
blo | 💥 8,197 | | | | SVG |
ethereum-blockies-base64 | 807 | | | | PNG |
blockies-react-svg | 1,749 | | | | SVG |
@download/blockies | 334 | | | | Canvas |
blockies-ts | 342 | | | | Canvas |
react-blockies | 2,361 | | | | Canvas |
Getting Started
npm i -S blo
pnpm add blo
yarn add blo
import { blo } from "blo";
img.src = blo("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
React / Vue / Others
blo is fast enough to not require memoization or async rendering for common use cases.
function AddressIcon({ address }: { address: `0x${string}` }) {
return (
<img
alt={address}
src={blo(address)}
/>
);
}
API
blo(address: Address, size = 64): string
Get a data URI string representing the identicon as an SVG image.
The size
paramater shouldn’t usually be needed, as the image will stay sharp no matter what the size of the img
element is.
Example:
import { blo } from "blo";
img.src = blo(address);
img2.src = blo(address, 24);
bloSvg(address: Address, size = 64): string
Same as above except it returns the SVG code instead of a data URI string.
bloImage(address: Address): BloImage
Get a BloImage
data structure that can be used to render the image in different formats.
See src/svg.ts
for an example of how to use it.
Types
The library ships with TypeScript types included.
export type BloImage = [BloImageData, Palette];
export type BloImageData = Uint8Array;
export type Palette = [
Hsl,
Hsl,
Hsl,
];
export type PaletteIndex =
| 0
| 1
| 2;
export type Hsl = Uint16Array;
export type Address = `0x${string}`;
Acknowledgements
FAQ
Does it follow the exact same algorithm as Etherscan, MetaMask and others?
Yes.
Does it work with ENS names?
No it only works with Ethereum addresses, but you can resolve the ENS name to an address (e.g. with wagmi) and pass the result to blo.
Can blo render other formats than SVG?
You can render to any format you want by using the bloImage()
function, which returns a data structure (see API above). Check out the Bun and Node demos for examples of rendering an identicon in the terminal.
Can it be used to generate other types of identicons?
blo only focuses on the Ethereum identicons algorithm but you can use it with any data, just prefix it with 0x
to fulfill the expected Address
type if you are using TypeScript.
Why is it named blo?
blo is short for blockies, which is the name of the original library it is based on.
License
MIT