Skip to content

Quickstart

In this guide you will find the address that holds a GitHub handle, and then the GitHub handle that address publishes. You only read from the chain, so you need no wallet and no tokens.

You need Node.js 20 or later, and a network that runs libID with some identities bound. Start the local chain first: it binds known handles, including octocat. When local.env is loaded, RPC_URL and IDENTITY_REGISTRY are set.

Create a project and install viem and the libID contracts package:

Terminal window
mkdir libid-quickstart && cd libid-quickstart
npm init -y
npm install viem @libid/contracts

IdentityRegistry is the contract that stores which address holds which identity: a platform account it has proved.

Create index.mjs:

import { createPublicClient, http } from 'viem';
import { platformId, resolveHandle, publishedHandleOf } from '@libid/contracts';
const registry = {
client: createPublicClient({ transport: http(process.env.RPC_URL) }),
address: process.env.IDENTITY_REGISTRY,
};
const github = platformId('github');

Every platform has an id. platformId('github') is the keccak256 hash of the string github. The other platforms are 'x' and 'google'.

Add this to index.mjs:

const holder = await resolveHandle(registry, github, 'octocat');
console.log(holder);

resolveHandle returns the address that proved it holds the handle, or null if nobody has. Handles are matched the way the platform matches them, so octocat, Octocat and @octocat are the same GitHub handle.

Now go the other way:

if (holder) {
const handle = await publishedHandleOf(registry, holder, github);
console.log(handle);
}

publishedHandleOf returns the handle the holder published on that platform. It returns null if the holder has not published one, or if the handle now belongs to someone else.

Terminal window
node index.mjs

On the local chain you will see:

0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
octocat

You can make the same call with Foundry’s cast:

Terminal window
cast call $IDENTITY_REGISTRY 'resolveHandle(bytes32,string)(address)' \
$(cast keccak github) octocat --rpc-url $RPC_URL

Set RPC_URL to the network’s RPC, and IDENTITY_REGISTRY to 0x0531b83b010a6b0c24c2c2c1a6beecc90cc71366, the address IdentityRegistry has on every public network. See Networks for what runs where.