0%

Torque: Money OS

A non-custodial digital wallet for individuals & businesses. Balances, execution, & settlement live in one interface—portfolio, trading, transfers, lending, borrowing, staking, & checkout—across the networks Torque supports. Unified liquidity & routing help you reach strong prices without juggling separate tools. Swap, send, & complete financial actions from the same wallet. Use Torque Assistant when you want conversational help.

Quick Example

Here is the server-route quick example with the important details spelled out (same as packages/torque-checkout/QUICK_START.md Option B).

Prereqs

  • Install: yarn add torque-checkout (or npm/pnpm).
  • Env in .env.local (server only, never commit):
.env.local
TORQUE_BUSINESS_ID=your_business_id_here
TORQUE_API_KEY=your_api_key_here
# optional; defaults to production Torque app
# TORQUE_BASE_URL=https://app.torque.fi

Next.js App Router route

handleCheckoutRequest() returns the function Next calls for POST: it await request.json() as a cart, uses env to talk to Torque, then responds with JSON.

app/api/checkout-session/route.ts
import { handleCheckoutRequest } from 'torque-checkout/nextjs'

// Returns the POST handler Next.js invokes: parse JSON cart → Torque → { success, checkoutUrl } or { success: false, error, code }
export const POST = handleCheckoutRequest()

Path name (checkout-session) is arbitrary; avoid clashing with Torque's hosted /api/torque-checkout on app.torque.fi.

Client call

  • Body: cart JSON — at least items (each line needs Torque productId) and customer with at least email.
  • Response: success → checkoutUrl (and expiresAt); failure → success: false, error, code, non-2xx status.
client-checkout.ts
const res = await fetch('/api/checkout-session', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    items: [{ productId: 'prod_123', quantity: 1 }],
    customer: { email: 'customer@example.com' }
  })
})
const data = await res.json()
if (!res.ok || !data.success || !data.checkoutUrl) {
  throw new Error(data.error ?? 'Could not start checkout')
}
window.location.href = data.checkoutUrl

Replace prod_123 with a real Torque product ID and the email with the shopper's email. Checkout SDK still covers install, env, and redirect; this pattern is the minimal your-server piece that keeps the API key off the client.

Was this helpful?