Install
The snippets below use Next.js App Router, but@opendatalabs/vana-sdk isn’t tied to Next — the server controller runs in any Node backend and the hook works in any React app. Use an existing Next.js project (or adapt the routes to your framework). To start fresh:
Configure the backend
Set server-side environment variables in.env.local:
.env.local
VANA_ENV=production for the current Direct app flow. Use VANA_NETWORK=moksha (testnet) — mainnet deployment is being finalized, so build on testnet for now.
Create lib/vana.ts:
lib/vana.ts
network — you don’t pass an address. Just fund escrow for your app on that network. (Pass an escrow config only to override the defaults for a custom deployment.) Replace source and scopes with values from the selected source detail or connector schema.
Create API routes
Create an access request route:app/api/vana/request/route.ts
app/connect/return/page.tsx
app/api/vana/status/route.ts
app/api/vana/data/route.ts
readApprovedData reads from the user’s Personal Server. If payment is required, the SDK signs the protocol challenge with your app key, pays from your app’s escrow using the network’s escrow contract and gateway, retries with X-PAYMENT, and returns the paid read result. If your app’s escrow balance is unfunded, the read fails with Insufficient finalized balance — fund escrow and retry.
Add React
The frontend calls your backend, opens Vana approval, polls status, asks your backend to read approved data, and renders the returned result.app/components/ConnectSpotifyButton.tsx
<ConnectSpotifyButton /> from a page in your app.