Wallet API supports registering a Basename using the arbitrary smart contract invocation feature. Basenames are the Base Layer 2’s human-readable address naming system that makes sending transactions simpler and helps you curate your onchain identity.
This solutions guide explains how you can register a Basename for your API Wallet, allowing anyone to easily send assets to your wallet and engage with your onchain identity.
See the GitHub repo for more information about cloning this quick start.
See the Replit template for more information about running the quick start on Base Sepolia testnet.
Replit for easy deployments
Replit is an AI-powered software development & deployment platform for building, sharing, and shipping software fast.
Coinbase has partnered with Replit to create a template that enables developers to register their AI agent onchain
in just minutes.
Have a persisted funded API Wallet on the Base network (minimum of 0.005 Base mainnet ETH). See creating a wallet to quickly spin up a 1-of-1 Developer-Managed wallet, and refer to persisting a wallet for more information on how to save it.
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";import { encodeFunctionData, namehash } from "viem";import { normalize } from "viem/ens";import os from "os";
Set up the ABIs for the L2 Resolver and Registrar contracts, and define the BaseNamesRegistrarControllerAddress.
The Registrar contract is responsible for registering Basenames. By calling the contract alongside an ETH payment, you buy the name and associate it with your address on the Resolver.
The Resolver is what allows wallets to resolve a certain Basename to its proper address.
Here, we’ll be using the information returned when persisting the wallet to import the wallet and register a Basename. Save these values as environment variables by running the following commands:
async () => { try { const { BASE_NAME, WALLET_ID, SEED_FILE_PATH } = process.env; // Manage CDP Secret API Key for Coinbase SDK. // Configure location to CDP Secret API Key. Coinbase.configureFromJson({ filePath: `${os.homedir()}/Downloads/cdp_api_key.json`, }); // Fetch funded Wallet. const wallet = await fetchWalletAndLoadSeed(WALLET_ID, SEED_FILE_PATH); const defaultAddress = await wallet.getDefaultAddress(); // Register Basename. const registerArgs = createRegisterContractMethodArgs(BASE_NAME, defaultAddress.getId()); await registerBaseName(wallet, registerArgs); } catch (error) { console.error(`Error in registering a Basename for my wallet: `, error); }};
Now that you have registered a Basename for your wallet, reach out to us in the #wallet-api channel of the CDP Discord if you have any questions or would like to see more solutions guides!