The Self playground provides an example usage of Self.
The main page app/page.tsx imports @selfxyz/qrcode and displays an interface to edit the attributes that should be revealed.
The API endpoint pages/api/verify.ts imports @selfxyz/core, receives proofs from the Self mobile app and verifies them.
To keep track of which session asks for which attributes, we store a mapping from user identifier to attributes to reveal using Vercel's key value database.
If you're looking for a simpler example that checks a set of fixed attributes, checkout happy-birthday instead.
- Fork the project and add it to your Vercel account.
- On Vercel, in
Storage, configure an Upstash For Redis database. Copy.env.exampleto.envand add your environment variables. - Environment routing:
SELF_ENVis the single source of truth for the active Self environment.next.config.jsre-exposes it to the client asNEXT_PUBLIC_SELF_ENV, so the QR payload and backend verifier stay aligned. SetSELF_ENV=stagingon the staging Vercel project only. LeaveSELF_ENVunset on the production Vercel project. If you use Vercel Preview deployments to exercise staging behavior, setSELF_ENV=stagingat the Preview scope too. Unset Preview vars on the production project will resolve to production behavior. Local development defaults to staging whenSELF_ENVis unset, and.env.examplesetsSELF_ENV=stagingsoyarn devdoes not hit production endpoints by default.SELF_VERIFY_ENDPOINT_OVERRIDEis optional and lets you override the verify endpoint for both client and server without editing tracked code. Note: Vercel only applies environment variable changes to new deployments — both server and client will keep using the previous values until you redeploy.NEXT_PUBLIC_SELF_ENVandNEXT_PUBLIC_SELF_VERIFY_ENDPOINT_OVERRIDEare additionally inlined into the client bundle at build time, so the client cannot pick up changes any earlier than that redeploy either. - Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev- Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
When developing locally, you can route the requests from the mobile app to your local machine by opening an ngrok endpoint using ngrok http 3000 and setting SELF_VERIFY_ENDPOINT_OVERRIDE to the generated URL, for example https://198c-166-144-250-126.ngrok-free.app/api/verify.
The QR payload endpoint and the SelfBackendVerifier endpoint must stay aligned or verification will fail because the SDK hashes the endpoint into the proof scope.