Step 3 – Add an Off-Chain Identity Layer (Magmar Auth)
Magmar Smart Accounts are wallet-agnostic, so we need a conventional method to map a real-world user to an on-chain account before we can mint NFTs on their behalf. For this tutorial we’ll use Userbase, a quick, server-less identity service to keep things simple. Remember: this is fine for demos, not for production.
3.1 Install and Configure Userbase
Install the SDK
npm i userbase-jsCreate a Userbase project
Visit https://userbase.com and sign up
After login, you’ll see a default Starter App → copy its App ID
Add environment variables
# .env.local
NEXT_PUBLIC_USERBASE_APP_ID=<YOUR_APP_ID>
NEXT_PUBLIC_exposes the value to the browser—required by the SDK.
Generate an access token
In the dashboard, open Account → Access Tokens
Label it
magmar-get-userand click Generate
Add the token to .env.local:
USERBASE_ACCESS_TOKEN=<YOUR_ACCESS_TOKEN>3.2 Create an AuthProvider
AuthProviderInside /common, add AuthProvider.tsx:
3.3 Wrap the App with AuthProvider
AuthProviderModify app/layout.tsx (Next 13 App Router):
We restrict chains to Sepolia to keep testnet usage safe.
3.4 Result
Any component can now call useAuth() to read or update the current user:
You’ve connected an off-chain identity system to Magmar Smart Accounts. Next we’ll create Sign-Up and Login routes that:
Generate a private key for the user
Derive their deterministic smart-contract wallet address
Store both in Userbase (plaintext only for demo!)
Last updated