In Next.js you call x402 endpoints from server code — a route handler or server action — so your wallet key never reaches the browser. The @2sio/sdk client does the rest.
Keep the wallet key in a server-only env var and call the endpoint inside an app-router route handler:
import { TwoS } from '@2sio/sdk'
const client = new TwoS({ privateKey: process.env.EVM_PRIVATE_KEY as `0x${string}` })
export async function GET() {
const res = await client.weather.zip({ zip: '94103' })
return Response.json(res.data) // real NWS forecast, paid per call
}Never put a funded wallet key in client components or NEXT_PUBLIC_ vars — it would be exposed in the browser bundle. Call x402 endpoints from route handlers, server actions, or server components only, and return just the data to the client.
Use trial mode while building so you do not spend anything during development:
const client = new TwoS({ trial: true }) // free real calls, no keyCall a live x402 API right now — no signup.
Browse the full endpoint directory, grab the quickstart, or read the llms.txt manifest. Every endpoint is keyless and pay-per-call.