Add Basenames to your onchain app
Basenames is now live! But what exactly is it? Basenames allows users to register human-readable names for their addresses and serves as a foundational building block for onchain identity. Think of it as your favorite social media handle, but even bigger. Your Basename is multichain by default and yours forever—no platform can take it away from you (just make sure to pay your fee). Integrating Basenames into your onchain app enhances the user experience by masking complex wallet addresses. Just as domains simplify IP addresses, Basenames do the same for wallet addresses. This tutorial shows you how to display Basenames on behalf of your users. We’ll walk through setting up the necessary files and configurations to interact with the Basenames ENS resolver directly. Let’s begin!Objectives
By the end of this tutorial, you should be able to:- Understand how onchain identity works on the Base network
- Enable users to use their onchain identity in your app
- Pull metadata from your users’ Basename profile
Steps
First, create a directory to store the ABI (Application Binary Interface) for the Basenames ENS resolver. The ABI will allow your project to interact with the smart contract that handles Basenames. In your project folder, run the following commands:abis
and a file named L2ResolverAbi.ts within it.
Next, add the following placeholder code to the L2ResolverAbi.ts
file:
You will need to replace the placeholder comment with the actual ABI. Here is the link to the full L2ResolverAbi.
wagmi.ts
convertReverseNodeToBytes()
: This function is creating the reverse node so we can look up a name given an address. Each address gets its own reverse record in our registry that’s created in a deterministic way.
You can see the implementation of convertReverseNodeToBytes()
in the OnchainKit repo
BasenameTextRecordKeys
: Metadata (e.g., github, twitter, etc.) are stored as text records so we can look them up based on the enum key.src/apis/basenames.tsx
You can find the complete implementation in the full basenames.tsx file.
page.tsx
file to display Basename information on the server and client side.
Here’s how to set it up:
src/app/page.tsx