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.
- 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.
Install the package using npm or yarn:
npm install @superdevfavour/basename
Or
yarn add @superdevfavour/basename
Here's how to use the package in your TypeScript or JavaScript project:
import {
getBasename,
getBasenameAvatar,
getBasenameTextRecord,
getBasenameTextRecords,
BasenameTextRecordKeys,
} from "basename";
const address: Address = "0x1234...abcd";
const basename = await getBasename(address);
console.log(basename); // Output: example.base.eth
const avatar = await getBasenameAvatar("example.base.eth");
console.log(avatar); // Output: Avatar URL
const description = await getBasenameTextRecord(
"example.base.eth",
BasenameTextRecordKeys.Description
);
console.log(description); // Output: ENS description
const allRecords = await getBasenameTextRecords(
"example.base.eth",
BasenameTextRecordKeys
);
console.log(allRecords); // Output: { description: "...", url: "...", ... }
Fetches the ENS basename (e.g., example.base.eth
) associated with a given Ethereum address.
-
Parameters:
address
: Ethereum address of typeAddress
fromviem
.
-
Returns:
- A
Promise
that resolves to astring
representing the basename.
- A
Retrieves the avatar URL for a given ENS basename.
-
Parameters:
basename
: The ENS basename, such asexample.base.eth
.
-
Returns:
- A
Promise
that resolves to astring
containing the avatar URL.
- A
Fetches a specific text record from the ENS basename.
-
Parameters:
basename
: The ENS basename, such asexample.base.eth
.key
: ABasenameTextRecordKeys
enum representing the desired text record.
-
Returns:
- A
Promise
that resolves to the text record value.
- A
Fetches all text records associated with the ENS basename.
-
Parameters:
basename
: The ENS basename, such asexample.base.eth
.key
: An arrayBasenameTextRecordKeys
enum to define the type of records.optional
-
Returns:
- An
Promise
that resolves to an object containing all text records.
- An
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"