ENS Offchain Subnames + Privy Starter Kit
A Next.js starter integrating the Offchain Manager SDK with Privy for creating and managing offchain ENS subnames.Features
- Privy auth with embedded wallets and Wagmi
- Offchain subname creation via secure API routes
- Reverse resolution for addresses, e.g.,
0x23...
βhappy.offchainsub.eth
- Preferred identity resolution (subname β ENS β truncated address)
- Account modal with username creation and avatar upload
thenamespace/ens-subnames-privy-template
Prerequisites
- Node.js (v18 or later)
- An ENS name (e.g.,
namespace.eth
) - Namespace API key from the Dev Portal
- Privy App ID and Client ID (create via Privy Dashboard:
dashboard.privy.io/account
)
Setup
1
Use as a template or clone
Use GitHubβs template feature:
- Open:
thenamespace/ens-subnames-privy-template
- Click βUse this templateβ β βCreate a new repositoryβ
- Clone your new repository locally
2
Environment variables
Copy Notes:
.env.example
to .env.local
in the project root and fill in values:- Do not expose server-only secrets in client code. The API key is used only server-side.
- If you change domains or networks, update the SIWE values accordingly.
3
Configure Privy
- Sign up/sign in to the Privy Dashboard:
dashboard.privy.io/account
- Create a new app (Web)
- In App settings β Client tab, copy your App ID and Client ID
- Add both to
.env.local
asNEXT_PUBLIC_PRIVY_APP_ID
andNEXT_PUBLIC_PRIVY_CLIENT_ID
4
Configure your ENS name
- Visit the Namespace Dev Portal
- Change the resolver for your ENS name to Namespaceβs resolver
- Generate and copy your Namespace API key
- Add it to your
.env.local
asNAMESPACE_API_KEY
5
Run the development server
http://localhost:3000
to see the application.6
It's ready!

Whatβs included
π Privy Integration
- Privy authentication with embedded wallets
- Wagmi setup for EVM interactions
- Account modal with subname creation and avatar upload
- Automatic primary name resolution
File Structure
ποΈ Architecture
- Server-side Namespace client (
/src/lib/namespace.ts
) - Uses API key securely for write operations - Client-side Namespace client (
/src/lib/namespace-client.ts
) - For read-only operations without API key exposure - API routes (
/src/app/api/subname/*/route.ts
) - Server-side write operations (create subname, update avatar) - Providers (
/src/app/providers.tsx
) - Privy + Wagmi + React Query providers
πͺ Custom Hooks
useSubnames
- Fetch subnames for an address and build preferred identityuseIdentity
- Combine ENS with preferred identityuseUploadAvatar
- SIWE + upload avatar + update text recorduseUpdateEnsAvatar
- Helper to update avatar via server API
π‘ API Endpoints
POST /api/subname/create
- Create subnames with custom address and text recordsPOST /api/subname/avatar
- Update an ENS avatar text record for a subname
Security & Limitations
β οΈ Important Security Notes
- Never expose your
NAMESPACE_API_KEY
to the client side - API key is only used in server-side code (
/src/lib/namespace.ts
and API routes) - Client-side operations use the public client without API key
- All write operations happen in API routes or server-side code only
- Validate and sanitize inputs in API routes
π Rate Limits
- Up to 2,000 subnames can be created per API key to prevent abuse
- Need more? Contact us on the Builders Group
References
- GitHub Repository:
thenamespace/ens-subnames-privy-template
- SDK Reference: Offchain Manager SDK
- Privy Dashboard:
dashboard.privy.io/account
- Privy Docs:
docs.privy.io
- Wagmi:
wagmi.sh