Skip to content

Latest commit

 

History

History
219 lines (180 loc) · 8.3 KB

records.mdx

File metadata and controls

219 lines (180 loc) · 8.3 KB

{/* * @type {import('@/lib/mdxPageProps').MdxMetaProps} */} export const meta = { description: '', emoji: '🔍', contributors: [ 'lucemans' ] };

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.

nick.eth ➡️
{ [ ["display", "Nick.eth"], ["description", "Lead developer of ENS"], ["avatar", "ipfs://Qm..."], ["com.twitter", "nicksdjohnson"], ].map(([key, value]) => (
{key} {value}
)) }

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.

Getting Records

To fetch the record for a specific name, you can use one of the following methods:

import { useRecords } from "ens-tools/react";

export const MyProfile: FC<{ name: string }> = ({ name }) => {
    const { data } = useRecords({
        name: name,
        records: ["com.twitter", "com.github", "description"],
        normalize: true,
    });

    return (
        <div>
            {data.map((record) => (
                <div key={record.key}>
                    {record.key}: {record.value}
                </div>
            ))}
        </div>
    );
};
// Warning, wagmi does not include a nice "hook" for records yet.
// We recommend you use ENS Tools or Viem for now.

import { useContractRead } from "wagmi";

export const MyProfile: FC<{ name: string }> = ({ name }) => {
    const {} = useContractRead({
        address: "0xc0497E381f536Be9ce14B0dD3817cBcAe57d2F62",
        abi: universalResolverABI,
        functionName: "resolve",
        args: [
            "", // DNS Encoded ENS name (eg luc.eth)
            [
                "", // Array of wildcard resolution calldata
                "",
            ],
        ],
        chainId: 1,
    });
    // TODO: This demo outputs [ calldata_result[], resolver_address]

    return <>TODO</>;
};
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",
});
// 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)
}

Types of Records

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 A list of comma-separated keywords ENSIP-5 person, ens
email Email Address ENSIP-5 luc@ens.domains
mail A physical mailing address ENSIP-5 V3X HQ
notice A notice regarding this name ENSIP-5 This is a notice
location A generic location (e.g. "Toronto, Canada") ENSIP-5 Breda, NL
phone A phone number as an E.164 string ENSIP-5 +1 234 567 890
url a website URL ENSIP-5 https://ens.domains

Other Records

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.

Header/Banner Record

An example of a "yet to be standardised" record is the "header" record. From initial community usage 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.

{ ["luc.eth", "pedrouid.eth", "notben.eth"].map(async (name) => { const request = await fetch("https://worker.enstate.rs/n/" + name); const data = await request.json();
            return (
                <div className="card !p-0 !m-0 w-fit">
                    <div className="h-20 aspect-[3/1]">
                        {data?.header && (
                            <img
                                src={data.header}
                                className="w-full h-full object-cover"
                            />
                        )}
                    </div>
                    <div className="w-16 h-16 aspect-square bg-ens-light-background-primary dark:bg-ens-dark-background-primary rounded-full mx-auto z-20 relative -mt-8 overflow-hidden">
                        {
                            data?.avatar && <img src={data.avatar} className="w-full h-full object-cover" />
                        }
                    </div>
                    <div className="text-center">
                        {name}
                    </div>
                </div>
            )
        })
    }
</div>

Setting Records

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.