1.2.0 β€’ Published 6 months ago

blo v1.2.0

Weekly downloads
12
License
MIT
Repository
github
Last release
6 months ago

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

LibraryRenders/sec^1SizeTypesEnvironment^2Rendering
bloπŸ’₯ 8,197npm.ionpm.ionpm.ioSVG
ethereum-blockies-base64807npm.ionpm.ionpm.ioPNG
blockies-react-svg1,749npm.ionpm.ionpm.ioSVG
@download/blockies334npm.ionpm.ionpm.ioCanvas
blockies-ts342npm.ionpm.ionpm.ioCanvas
react-blockies2,361npm.ionpm.ionpm.ioCanvas

^1: The number of renders per second. It was measured on Chrome 117 Linux with an AMD Ryzen 7 PRO 4750U. See ./benchmark for the methodology.

^2: The term β€œall” refers to libraries that are framework agnostic and that run in browsers, Bun and Node.js.

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

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); // size inside the SVG defaults to 64px
img2.src = blo(address, 24); // set it to 24px

Same as above except it returns the SVG code instead of a data URI string.

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.

// BloImage contains the data needed to render an icon.
export type BloImage = [BloImageData, Palette];

// 4x8 grid of the image left side, as 32 PaletteIndex items.
// The right side is omitted as it's a mirror of the left side.
export type BloImageData = Uint8Array;

// Colors used by a given icon.
export type Palette = [
  Hsl, // background
  Hsl, // color
  Hsl, // spot
];

// Points to one of the three Palette colors.
export type PaletteIndex =
  | 0 // background
  | 1 // color
  | 2; // spot

// A color in the HSL color space.
// [0]: 0-360 (hue)
// [1]: 0-100 (saturation)
// [2]: 0-100 (lightness)
export type Hsl = Uint16Array;

// An Ethereum address.
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

1.2.0

6 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.3.0

1 year ago

0.4.4

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.2.1

13 years ago

0.2.0

13 years ago

0.1.0

13 years ago