Skip to main content

ENS offchain subnames with Openfort

A Next.js starter kit integrating the Offchain Manager SDK with Openfort Embedded Wallets for creating and managing offchain ENS subnames.

Features

  • Openfort Embedded Wallets with Wagmi
  • Automatic recovery via Shield session endpoint
  • Offchain subname creation via secure API routes
  • Preferred identity resolution (subname → ENS → truncated address)
  • Account modal with username creation and avatar upload
Repository: thenamespace/ens-subnames-openfort-template

Prerequisites

  • Node.js v18+
  • An ENS name you control (e.g., namespace.eth)
  • Namespace API key from the Namespace App
  • Openfort account with API keys and Shield keys
1

Use the template

2

Openfort environment variables

  1. Open the Openfort Dashboard and create an app
  2. Copy your publishable key, secret key, and Shield keys
  3. Create .env.local and add:
Notes:
  • Never expose server-only secrets to the client.
  • The recovery endpoint returns a Shield encryption session for automatic wallet recovery.
3

Namespace environment variables

  1. Visit the Namespace App
  2. Set your ENS name and Namespace API key (see Namespace App API keys):
4

Optional: Avatar + SIWE variables

For avatar uploads and SIWE, add:
5

Run the development server

Open http://localhost:3000 to see the application.
6

It's ready!

Create subname interface with form to create a new offchain subname

What’s included

🔐 Openfort Integration

  • Openfort Embedded Wallets with automatic recovery via Shield
  • Wagmi setup for EVM interactions
  • Account modal with subname creation and avatar upload
  • Automatic primary name resolution

File Structure

🏗️ Architecture

  • Providers (/src/app/providers.tsx) - Openfort + Wagmi + React Query
  • Server-side Namespace client (/src/lib/namespace.ts) - Uses API key for writes
  • Client-side Namespace client (/src/lib/namespace-client.ts) - Read-only, no API key exposure
  • API routes (/src/app/api/*/route.ts) - Server-side write operations and Shield session

🪝 Custom Hooks

  • useSubnames - Fetch subnames and build preferred identity
  • useIdentity - Combine ENS with preferred identity
  • useUploadAvatar - SIWE + upload avatar + update text record
  • useUpdateEnsAvatar - Helper to update avatar via server API

📡 API Endpoints

  • POST /api/shield-session - Returns Shield encryption session for automatic recovery
  • POST /api/subname/create - Create subnames with custom address and text records
  • POST /api/subname/avatar - Update an ENS avatar text record for a subname

Security & Limitations

⚠️ Important Security Notes

  • Never expose your NAMESPACE_API_KEY, OPENFORT_SECRET_KEY, SHIELD_SECRET_KEY, or SHIELD_ENCRYPTION_SHARE to the client side
  • Server-only keys are used only in server-side code (/src/lib/namespace.ts, Shield session route, and API routes)
  • Client-side operations use the public client without API key
  • 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