Get text records
Read text records such as a URL, a description or a social handle from a name, one key at a time or many keys in one call.
By the end of this guide you can read one text record (a key and a string value that a name's owner stores, such as url or com.twitter), or load several at once.
Prerequisites
- An ensforge client with the ENS actions added. See Create a client.
Read one record
record.getText reads a single text record. Pass the name and the record's key.
Example (Reading a Profile URL)
import { ensActions, Ensforge } from "@ensforge/sdk";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
const ens = Ensforge.create({
publicClient: createPublicClient({ chain: mainnet, transport: http() }),
}).extend(ensActions());
const url = await ens.record.getText({ name: "nick.eth", key: "url" });The result is a string, or null when the record is not set. ensforge normalises the name and finds its resolver, so wildcard names and off-chain names work too. Calls made in the same tick are batched into one multicall where possible. See record.getText and How a lookup works.
Read several records in one call
record.get reads any mix of records in one request. List the keys in texts, and the result has exactly the fields you asked for.
Example (Loading a Profile)
import { ensActions, Ensforge } from "@ensforge/sdk";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
const ens = Ensforge.create({
publicClient: createPublicClient({ chain: mainnet, transport: http() }),
}).extend(ensActions());
const profile = await ens.record.get({
name: "nick.eth",
texts: ["avatar", "url", "com.twitter"],
addresses: ["eth", "btc"],
});
profile.texts.url;
profile.addresses.btc;
profile.resolver;textslists text keys. Each key becomes a field ofprofile.texts, typedstring | null.addresseslists coins by symbol or coin type. Each becomes a field ofprofile.addresses.resolveris the address of the resolver that answered, ornullwhen the name has none.- A field you did not ask for does not exist on the result:
profile.texts.urlis there only because"url"was requested.
record.get is one Universal Resolver call whatever you select. It can also read the content hash (contentHash: true), the public key, the name record and more. See record.get, Get a name's address and Get a website.
Options
record.getText takes:
| Option | Type | Default | Description |
|---|---|---|---|
name | string | required | The name to read. Normalised for you. |
key | string | required | The text record key, such as url, avatar or com.twitter. |
record.get takes name and any of these selections:
| Option | Type | Default | Description |
|---|---|---|---|
texts | readonly string[] | none | Text record keys to read. |
addresses | readonly (string | bigint)[] | none | Coins to read, by symbol or coin type. |
contentHash | true | none | Read the content hash. |
abi | true or { contentTypes: bigint } | none | Read the ABI record. |
pubkey | true | none | Read the public key. |
nameRecord | true | none | Read the name record. |
interfaces | readonly Hex[] | none | ERC-165 interface IDs to look up implementers for. |
data | readonly string[] | none | Data record keys. |
Both actions also take the options every read takes: signal to cancel, strict to throw instead of returning null, gatewayUrls for off-chain lookups, and blockNumber or blockTag to read at one block.
Troubleshooting
A record is null
The record is not set, the name has no resolver, or its resolver does not store text records. With strict: true, getText fails with RECORD_NOT_FOUND, RESOLVER_NOT_FOUND or RESOLVER_PROFILE_UNSUPPORTED, so you can tell which. record.get with strict: true fails with RESOLVER_NOT_FOUND when the name has no resolver. Without strict, it returns resolver: null and every record null.
INVALID_NAME
The name cannot be normalised. INVALID_NAME is thrown before any request is sent.
GATEWAY_REQUEST_FAILED
The name's resolver sends the lookup to an off-chain gateway, and the gateway failed. See Look up off-chain names and GATEWAY_REQUEST_FAILED.
Was this page helpful?