Overview

Metadata records are custom key-value pairs you can attach to an offchain ENS subname. They are not used for onchain ENS resolution but are useful for discovery and filtering (e.g., via getFilteredSubnames) because they are indexed in the Namespace offchain service.

Methods

1. addDataRecord

Adds or updates a metadata record for the specified subname.

Usage Example

try {
  await client.addDataRecord({
    subname: "ns.myensname.eth",
    key: "token-holder",
    data: "1200", // number of tokens held by the owner
  });
  console.log("Metadata saved.");
} catch (error) {
  // Handle network, auth, or validation errors
  console.error("Failed to add data record:", error);
}
  • subname: The full ENS subname (e.g., "ns.myensname.eth").
  • key: Case-sensitive metadata key (e.g., "token-holder").
  • data: Value to store for the key (string).
If the key already exists, its value will be overwritten.

2. deleteDataRecord

Deletes a data record from the subname.

Usage Example

try {
  await client.deleteDataRecord({
    subname: "ns.myensname.eth",
    key: "token-holder",
  });
  console.log("Metadata key deleted.");
} catch (error) {
  console.error("Failed to delete data record:", error);
}
  • subname: The full ENS subname.
  • key: The metadata key to delete.

3. getDataRecords

Returns all data records of the provided subname as a key-value map.

Usage Example

const allMetadata = await client.getDataRecords("ns.myensname.eth");
// allMetadata: Record<string, string>

Return Type

type DataRecords = Record<string, string>;
Example Result
{
  "token-holder": "1200",
  "segment": "pro",
}

4. getDataRecord

Returns the requested data record for the provided subname and key.

Usage Example

const response = await client.getDataRecord("ns.myensname.eth", "token-holder");
const data = response.record; // "1200"

Return Type

export interface GetRecordResponse {
  record: string;
}
  • record: The value associated with the requested key.