On this page
Nimiq Identicons
A simple, visually recognizable way to verify addresses.
More than 9 Million combintations!
Each Identicon is a unique combination of colors and shapes based on an account's hash, providing instant visual confirmation.
Download
Installation
To start using Nimiq Identicons in your project, run:
bash
npm install identicons-esm
bash
yarn add identicons-esm
bash
pnpm add identicons-esm
bash
bun add identicons-esm
Basic Usage
Import and create an identicon using createIdenticon
:
ts
import { createIdenticon } from 'identicons-esm'
const input = 'Your input here'
const svg = await createIdenticon(input)
Customization
For specific colors or sections of the identicon, use getIdenticonsParams
:
ts
import { ensambleSvg, formatIdenticon, getIdenticonsParams } from 'identicons-esm'
const input = 'Your input here'
const { colors, sections } = await getIdenticonsParams(input)
// You can modify any parameter as you wish
// colors.background, colors.main, colors.accent
// sections.top, sections.bottom, sections.sides, sections.face (SVG paths)
// Generate SVG string
const customSvg = ensambleSvg({ colors, sections, /* Other optional values to overwrite default backgroundShape, innerShadow, circleShape */ })
// Also possible to change the Identicon format
const formatted = formatIdenticon(customSvg, { format: 'image/svg+xml' })
Migration from Legacy
This module has updated performance and packaging over the legacy version.
Generating a SVG
Old
js
import Identicons from '@nimiq/identicons/dist/identicons.min.js'
IdenticonsLegacy.svgPath = '@nimiq/identicons/dist/identicons.min.svg'
const input = 'Your input here'
const svg = await Identicons.svg(input)
New
js
import { createIdenticon } from 'identicons-esm'
const input = 'Your input here'
const svg = await createIdenticon(input)
Generating a Data URI
Old
js
import Identicons from '@nimiq/identicons/dist/identicons.min.js'
IdenticonsLegacy.svgPath = '@nimiq/identicons/dist/identicons.min.svg'
const input = 'Your input here'
const svg = await Identicons.toDataUri(input)
New
ts
import { createIdenticon } from 'identicons-esm'
const input = 'Your input here'
const svg = await createIdenticon(input, { format: 'image/svg+xml' })
Discontiuned functions
There are functions in the original library that are not included in this implementation due to lack of use. These functions are:
makeLetterHash
wordsByEntropy
Identicons.render
Identicons.image
Identicons.placeholder