ENS Logo
Docs

Primary Names

We can all agree 42-character long machine-optimized addresses (eg. 0x2ac...f231) are not aesthetically pleasing. Fortunately, it is super easy to retrieve a user's preferred name, and this page will show you how.

0x225...c3B5to
legend.root

In order to convert them to human-readable names, we use reverse registrar. The reverse registrar is a smart contract that allows users to register their preferred name, referred to as their "primary name" for simplicity purposes.

Getting a Primary Name

To get a users preferred primary name is very simple. In most libraries you will find a function to do a lookup by address as shown below. This allows us to turn any address into a human-readable name.

Reverse Lookup
import { ethers } from 'ethers';
import { networks } from 'rootnameservice'

const provider = new ethers.providers.JsonRpcProvider('https://root.rootnet.live/archive', networks.root);
// 0x03E53414a65AF0723D8dAb6dFBA768E061E5d81f -> legend.root
provider.lookupAddress(
  '0x03E53414a65AF0723D8dAb6dFBA768E061E5d81f'
).then(console.log)
import { getName } from '@ensdomains/ensjs/public'
import { createPublicClient, defineChain, Address, http } from 'viem'
import { addresses } from 'rootnameservice'

const root = defineChain({
  id: 7668,
  name: 'The Root Network',
  nativeCurrency: { name: 'Ripple', symbol: 'XRP', decimals: 18 },
  rpcUrls: {
    default: {
      http: ['https://root.rootnet.live/archive'],
    },
  },
  contracts: {
    ...addresses[7668],
  },
  subgraphs: {
    ens: {
      url: 'https://subgraph.rootnameservice.com/subgraphs/name/graphprotocol/ens/graphql',
    },
  },
  testnet: true,
})

const client = createPublicClient({
  chain: root,
  transport: http(),
})

// 0x03E53414a65AF0723D8dAb6dFBA768E061E5d81f => legend.root
getName(client, {
  address: "0x03E53414a65AF0723D8dAb6dFBA768E061E5d81f" as Address, // put address you want to resolve
}).then(console.log)

🎉 And that's it! Now you can turn all your pages from this, to this:

0x2ac...f231
sent 0.1 root to
0x123...4567
turns into
legend.root
sent 0.1 root to
nrl.root