This guide will show you how to implement a subname minting functionality using Namespace-SDK
Namespace SDK is a typescript library, which can be used to interact with Namespace API and smart contracts. It currently allows devs to mint subnames under listed ENS names and abstracts the different chain logic.
1. Listing an ENS name
The prerequisite for minting is for the parent ENS name to be listed on the Namespace platform. This can be done using the Manager on our platform.
For testing purposes, we can use an already listed name "mint-on-namespace.eth". This name is listed on the Sepolia testnet and the subnames will be minted on the BaseSepolia testnet.
The second step would be to include namespace-SDK dependency in our typescript project. Since the SDK uses viem under the hood, we would also need to include it as a dependency.
yarn add namespace-sdk viem
npm install namespace-sdk viem
3. Create a NamespaceClient instance
We will use createNamespaceClientfunction to set up a Namespace Client with a given ChainId.
The ChainId specifies an id of a blockchain where the subnames are being minted from (In our case, since we will be using "mint-on-namespace.eth", we will specify baseSepolia.id (84532), this is so that viem knows which chain to look at when it simulates the mint transaction or when it checks for subname availability.
3.1
Currently, when it comes to layer 2 subnames, Namespace supports two chains for mainnet and one testnet chain. The chainId parameter depends on the l2 chain where the name is listed.
import { NamespaceClient, ENS_NAME } from"./namespace-client";import { Listing } from"namespace-sdk";import { sepolia } from"viem/chains";constgetListedName=async():Listing=> {// Here, we're specifying sepolia id as a second parameter// since our name is listed on sepolia testnet// for names listed on mainnet, we do not need to provide a second parameterreturnNamespaceClient.getListedName(ENS_NAME,sepolia.id)}constisSubnameAvailable=async (listedName:Listing, subnameLabel:string):boolean=> {returnNamespaceClient.isSubnameAvailable(listedName, subnameLabel);}
5. Getting mint transaction parameters
Mint transaction parameters return all the needed values for executing a mint transaction
Now that we have all the required parameters, we can use all this to execute a mint transaction and mint a subname, using our preferred client library.
We have now minted a subname on the BaseSepolia chain! We can now verify that it gets resolved on the ENS app using the URL: https://app.ens.domains/your-full-name.eth ( remember to switch to the Sepolia network if you've been using mint-on-namespace.eth )
Chain
ChainId
Testnet
Parameter
Required
Description
Optimism
10
false
Base
8453
false
Base Sepolia
84532
true
chainId
true
Specifies chain id where subnames are minted from, supported chains include
mintSource
false
Used to track the source of minted subnames on a blockchain, defaults to "namespace-sdk".
rpcUrl
false
Http RPC URL which will be used by SDK when it performs blockchain operations, defaults to a public RPC for a given chain