Look up a wallet
A wallet can hold several identities, on one platform or on many. This guide shows how to get the one handle a wallet shows as its name, and how to list all of its identities.
The examples use this setup:
import { createPublicClient, http } from 'viem';import { identityCount, identitiesOf, platformId, primaryHandleOf } from '@libid/contracts';
const client = createPublicClient({ transport: http(process.env.RPC_URL) });const registry = { client, address: process.env.IDENTITY_REGISTRY };
const holder = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8';Show a handle
Section titled “Show a handle”To show a wallet by its handle in your app, use primaryHandleOf:
const primary = await primaryHandleOf(registry, holder);console.log(primary?.handle ?? holder);Each holder has at most one primary handle, on any platform.
primaryHandleOf returns it with its platformId, or null if the holder
has not chosen one. It also returns null if the handle now belongs to
someone else, so you never show a handle the holder has lost. See
Primary handle.
List every identity
Section titled “List every identity”identitiesOf returns the identities a holder has, on every platform, one
page at a time. identityCount tells you how many there are:
const count = await identityCount(registry, holder);const identities = await identitiesOf(registry, holder, 0n, 10n);
for (const identity of identities) { console.log(identity.platformId, identity.idNode, identity.handleNode, identity.handleCurrent);}Each identity has:
platformId: the platform, asplatformId('github')computes it.idNode: the node of the id the platform issued, a SHA-256 hash of the id. It never changes.handleNode: the node of the handle this identity proved most recently.handleCurrent:falseif another identity has since proved the same handle. Do not route payments by a handle when this isfalse.
The list has nodes, not the id or the handle as text. See
Platforms and nodes. To show a
handle, use primaryHandleOf. To check whether an identity proved a handle
you already know, compare its handleNode with
handleNode('github', 'octocat') from @libid/contracts.
The arguments after the holder are where the page starts and how many identities to return. To read a long list, move the start forward:
const all = [];for (let from = 0n; from < count; from += 10n) { all.push(...(await identitiesOf(registry, holder, from, 10n)));}The order of the list is not fixed. It can change when an identity moves to another holder. If you need an exact list, read the count and all pages at the same block.
One platform only
Section titled “One platform only”The list covers all platforms. To keep one, filter it:
const onGithub = all.filter((i) => i.platformId === platformId('github'));