Text Records
With every name come a set of records. These records are key value pairs that can be used to store information about the profile. Think of this as a user's digital backpack. Utalized for storage of preferences, public details, and more.
Text records allow us to attach and read any key value pair from an ENS name. The most popular records have been standardised. One example of a standardised record is the avatar record which is used to store a user's profile picture.
To fetch the record for a specific name, you can use one of the following methods:
import { useEnsText } from "wagmi";
import { normalize } from "viem/ens";
export const MyProfile: FC<{ name: string }> = ({ name }) => {
const { data } = useEnsText({
name: normalize("luc.eth"),
key: "com.twitter",
});
return (
<div>
<span>Twitter: {data}</span>
</div>
);
};
const provider = new ethers.providers.JsonRpcProvider();
const resolver = await provider.getResolver("luc.eth");
const twitter = await resolver.getText("com.twitter");
import { normalize } from "viem/ens";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const ensText = await publicClient.getEnsText({
name: normalize("luc.eth"),
key: "com.twitter",
});
from ens.auto import ns
# set text
ns.set_text('alice.eth', 'url', 'https://example.com')
# get text
url = ns.get_text('alice.eth', 'url')
assert url == 'https://example.com'
// TODO: Not Implemented
package main
import (
"fmt"
"github.com/ethereum/go-ethereum/ethclient"
ens "github.com/wealdtech/go-ens/v3"
)
func main() {
client, _ := ethclient.Dial("https://rpc.ankr.com/eth")
domain, _ := ens.Normalize("luc.eth")
resolver, _ := ens.NewResolver(client, domain)
twitter, _ := resolver.Text("com.twitter")
fmt.Println("Twitter: ", twitter)
}
Here are some of the most commonly used records:
Name | Usage | Reference | Example |
---|---|---|---|
display | Preferred capitalization | ENSIP-5 | Luc.eth |
avatar | Avatar or logo (see Avatars) | ENSIP-5 | ipfs://dQw4w9WgXcQ |
description | Description of the name | ENSIP-5 | DevRel @ ENS Labs |
keywords | List of comma-separated keywords | ENSIP-5 | person, ens |
Email address | ENSIP-5 | luc@ens.domains | |
Physical mailing address | ENSIP-5 | V3X HQ | |
notice | Notice regarding this name | ENSIP-5 | This is a notice |
location | Generic location (e.g. "Toronto, Canada") | ENSIP-5 | Breda, NL |
phone | Phone number as an E.164 string | ENSIP-5 | +1 234 567 890 |
url | Website URL | ENSIP-5 | https://ens.domains |
header | Image URL to be used as a header/banner | ENSIP-18 | ipfs://dQw4w9WgXcQ |
Currently there are a few records that have been standardised. However you are welcome to store any key value pair you desire.
We generally recommend to stick to a pattern, or prefix things with your app or protocol (eg. com.discord
, or org.reddit
), as such to avoid collisions.
One of the newer standardised records is the "header" record. This header record, similar to the avatar record, accepts any IPFS, Arweave, EIP155, or regular URL to an image resource. The image is then displayed as a banner on the profile page and tends to be in a 1:3 aspect ratio.
When records are loaded they are loaded from the resolver responsible for the name. As resolvers are user controlled, we cannot guarantee a write function is available. This makes it a more in-depth process to update a users records.