How to access the Ethereum Name Service (ENS) in your web3 app

Row of computers in a futuristic street illustrating ENS.
Row of computers in a futuristic street illustrating ENS.

In the world of Ethereum, addresses are stored and found using complex alphanumeric strings. Whether you're trying to send cryptocurrency or find someone's online profile, users often find themselves dealing with unwieldy addresses.

This is where the Ethereum Name Service (ENS) steps in, bringing human-friendly names to the blockchain realm. Much like how domain names made the internet user-friendly, ENS turns hexadecimal addresses into something as simple as vitalik.eth

Understanding ENS

The Ethereum Name Service (ENS) is a protocol established on the Ethereum blockchain, aiming to map readable names to various addresses. It's a means to simplify transactions and interactions in the blockchain space, replacing cumbersome addresses with easily memorable names. So instead of sending Ethereum to a string of random numbers and letters, you could send it to “johnsmith.eth”.

Why ENS Matters

ENS tackles a fundamental usability issue faced by blockchain users. By allowing the allocation of human-readable names to blockchain addresses, it significantly simplifies user interactions. Imagine not having to copy-paste a long string of characters every time you want to send or receive crypto. That’s the convenience ENS aims to provide.

How ENS Works

At its core, ENS operates using two smart contracts: the ENS Registry and Resolvers. The Registry keeps track of all domain names that are registered and their respective Resolvers. Resolvers, on the other hand, are responsible for translating human-readable names into machine-friendly addresses and vice versa.

To register and own a name, you can visit the ENS domain manager, search for the desired domain, and follow the prompt to register it.

Once registered, you can link this domain to your cryptocurrency address, allowing for simplified transactions.

Profiles

Text records within ENS allow for a richer and more personalized experience within Web3 apps.

By associating metadata with ENS domains, text records significantly enhance the discoverability and social connectivity in web3. For instance, rich profiles in apps like rainbow.me can utilize ENS to display a user's avatar, name, or even links to social media profiles.

This facilitates social interaction, where individuals can easily find and connect with others via linked social media handles like Twitter, GitHub, or email right from their Ethereum addresses.

ENS and Basement

For developers and platforms, integrating ENS could be a key usability enhancement. At Basement, we provide a GraphQL API that supports ENS, allowing for seamless interaction between your application and the Ethereum Name Service.

With just a few lines of code, you can look up ENS names, resolve addresses, and facilitate easier transactions for your users. You no longer need an expensive RPC node resulting in slow N+1 requests.

fragment ProfileFields on Profile {
  name
  avatar
  twitter: text(key: "com.twitter")
  email: text(key: "email")
}

query ResolveAddresses {
  addresses(
    addresses: [
      "gotu.eth"
      "0x17cd072cBd45031EFc21Da538c783E0ed3b25DCc"
      "wilsoncusack.eth"
    ]
  ) {
    address
    # Profile only returns a profile if the address was queried by its ENS name
    # Use reverseProfile to find the primary ENS for a name
    # Note: profile and reverseProfile do not necessarily match
    profile {
      ...ProfileFields
    }
    reverseProfile {
      ...ProfileFields
    }
  }

Summing Up

ENS is a leap towards making Ethereum and Web3 as accessible as the traditional web. By masking the technical complexity with human-readable names, ENS fosters a more user-friendly space, something that’s integral as we move towards the next billion users.

Further Reading