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/basenameOr
yarn add @superdevfavour/basenameHere'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.ethconst avatar = await getBasenameAvatar("example.base.eth");
console.log(avatar); // Output: Avatar URLconst description = await getBasenameTextRecord(
"example.base.eth",
BasenameTextRecordKeys.Description
);
console.log(description); // Output: ENS descriptionconst 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 typeAddressfromviem.
-
Returns:
- A
Promisethat resolves to astringrepresenting the basename.
- A
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
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
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
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"