You can assign a name to an account to make it easier to access. Account names can consist of alphanumeric characters and hyphens, and must be between 2 and 36 characters long. Account names must be unique within a single CDP project for each account type (e.g., all Solana accounts).You can assign an account name at the time of account creation, and retrieve it later using the name. The getOrCreateAccount method will create an account if it doesn’t exist, and return the existing account if it does.
Copy
Ask AI
import { CdpClient } from "@coinbase/cdp-sdk";import dotenv from "dotenv";dotenv.config();const cdp = new CdpClient();const accountName = "my-account";// If the account doesn't exist, it will be created.let evmAccount = await cdp.evm.getOrCreateAccount({name: accountName});console.log(`Created account with name ${evmAccount.name}.`);// If the account already exists, it will be retrieved.evmAccount = await cdp.evm.getOrCreateAccount({name: accountName});console.log(`Retrieved account with name ${evmAccount.name}.`);