@superdevfavour/basename v1.0.5
@superdevfavour/basename
A JavaScript/TypeScript utility that simplifies interactions with Ethereum Name Service (ENS) basenames, allowing you to retrieve basename information such as avatars, text records, and more. This package provides helper methods for working with ENS .base.eth domains.
Features
- Fetch basename for a given Ethereum address.
- Retrieve avatars associated with ENS basenames.
- Access various text records (e.g., description, social media handles) from ENS basenames.
Installation
Install the package using npm or yarn:
npm install @superdevfavour/basenameOr
yarn add @superdevfavour/basenameUsage
Here's how to use the package in your TypeScript or JavaScript project:
Importing the module
import {
getBasename,
getBasenameAvatar,
getBasenameTextRecord,
getBasenameTextRecords,
BasenameTextRecordKeys,
} from "basename";Example 1: Get a Basename from an Ethereum Address
const address: Address = "0x1234...abcd";
const basename = await getBasename(address);
console.log(basename); // Output: example.base.ethExample 2: Get an Avatar for a Basename
const avatar = await getBasenameAvatar("example.base.eth");
console.log(avatar); // Output: Avatar URLExample 3: Get Specific Text Records from a Basename
const description = await getBasenameTextRecord(
"example.base.eth",
BasenameTextRecordKeys.Description
);
console.log(description); // Output: ENS descriptionExample 4: Get All Text Records for a Basename
const allRecords = await getBasenameTextRecords(
"example.base.eth",
BasenameTextRecordKeys
);
console.log(allRecords); // Output: { description: "...", url: "...", ... }API Reference
getBasename(address: Address): Promise<string>
Fetches the ENS basename (e.g., example.base.eth) associated with a given Ethereum address.
Parameters:
address: Ethereum address of typeAddressfromviem.
Returns:
- A
Promisethat resolves to astringrepresenting the basename.
- A
getBasenameAvatar(basename: Basename): Promise<string>
Retrieves the avatar URL for a given ENS basename.
Parameters:
basename: The ENS basename, such asexample.base.eth.
Returns:
- A
Promisethat resolves to astringcontaining the avatar URL.
- A
getBasenameTextRecord(basename: string, key: BasenameTextRecordKeys): Promise<string>
Fetches a specific text record from the ENS basename.
Parameters:
basename: The ENS basename, such asexample.base.eth.key: ABasenameTextRecordKeysenum representing the desired text record.
Returns:
- A
Promisethat resolves to the text record value.
- A
getBasenameTextRecords(basename: string, key: BasenameTextRecordKeys): Promise<RecordResult[]>
Fetches all text records associated with the ENS basename.
Parameters:
basename: The ENS basename, such asexample.base.eth.key: An arrayBasenameTextRecordKeysenum to define the type of records.optional
Returns:
- An
Promisethat resolves to an object containing all text records.
- An
Enum: BasenameTextRecordKeys
This enum contains the keys that can be used to fetch various text records related to the basename.
- Available Keys:
Description: "description"Keywords: "keywords"Url: "url"Email: "email"Phone: "phone"Github: "com.github"Twitter: "com.twitter"Farcaster: "xyz.farcaster"Lens: "xyz.lens"Telegram: "org.telegram"Discord: "com.discord"Avatar: "avatar"