Help & Support

Fetch Usernames

This guide will help you with fetching Usernames from Lens API.

Fetch a Username

Use the fetchUsername function to fetch a single username by localName or ID.

import { fetchUsername } from "@lens-protocol/client/actions";
import { client } from "./client";
const result = await fetchUsername(client, {  username: {    localName: "alice",    // namespace: evmAddress("0x1234…"), - optional for custom namespaces  }});
if (result.isErr()) {  return console.error(result.error);}
// { ID: string, value: string, linkedTo: evmAddress, owner: evmAddress, ... }const username = result.value;

List Usernames

Use the paginated fetchUsernames action to fetch a list of Usernames based on the provided filters.

import { fetchUsernames } from "@lens-protocol/client/actions";
import { client } from "./client";
const result = await fetchUsernames(client, {  filter: {    localNameQuery: "tom",    // namespace: evmAddress("0x1234…"), - optional for custom namespaces  }});
if (result.isErr()) {  return console.error(result.error);}
// items: Array<Username>const { items, pageInfo } = result.value;

See the Pagination guide for more information on how to handle paginated results.