Integrate Onchain Payments
Cart-based checkout: line items use Torque product IDs from your catalog; pricing comes from Torque, not from arbitrary client-side amounts. Multiple tokens & chains where configured. Use it for storefronts, SaaS billing, or invoices that settle onchain without building custody, liquidity routing, or per-network calldata yourself.
Installation
yarn add torque-checkout
# React hooks: import from 'torque-checkout/react'
# Next.js route helper: import from 'torque-checkout/nextjs'Credentials: Business ID + API key from Business settings → API Integration. Env: TORQUE_BUSINESS_ID, TORQUE_API_KEY; optional TORQUE_BASE_URL (default https://app.torque.fi).
Basic Usage
Recommended (secrets on server): expose a Route Handler that wraps handleCheckoutRequest — the SDK calls hosted POST /api/torque-checkout with your Bearer API key.
import { handleCheckoutRequest } from 'torque-checkout/nextjs'
export const POST = handleCheckoutRequest()
// Request body includes items (productId + quantity) & customer; response includes checkoutUrlReact: useTorqueCheckout from torque-checkout/react — e.g. generateProductCheckout(productId, quantity, { email }) or cart helpers (see Developer Guide).
import { createTorqueCheckoutFromEnv } from 'torque-checkout'
// Reads TORQUE_BUSINESS_ID & TORQUE_API_KEY — use only in Node / server context
const torque = createTorqueCheckoutFromEnv()
const checkoutUrl = await torque.generateCartCheckoutUrl({
items: [{ productId: 'your-torque-product-id', quantity: 1 }],
customer: { email: 'customer@example.com' },
options: { metadata: { orderId: 'ord_123' } },
})Configuration
Accepted Tokens
import { createTorqueCheckout } from 'torque-checkout'
// businessId + apiKey are both required. Use only on the server when passing apiKey.
const torque = createTorqueCheckout({
businessId: process.env.TORQUE_BUSINESS_ID!,
apiKey: process.env.TORQUE_API_KEY!,
baseUrl: process.env.TORQUE_BASE_URL, // optional; default https://app.torque.fi
acceptedTokens: ['USDC', 'ETH'],
acceptedChains: [1, 8453, 42161],
theme: { primaryColor: '#aa5bff', borderRadius: 'full' },
webhookUrl: 'https://yoursite.com/api/webhooks/torque',
})Webhooks
Receive real-time notifications when payments complete:
import { NextRequest, NextResponse } from 'next/server'
import { verifyWebhookSignature } from 'torque-checkout'
export async function POST(req: NextRequest) {
const body = await req.text()
const signature = req.headers.get('x-torque-signature')
const isValid = verifyWebhookSignature(
body, signature, process.env.TORQUE_WEBHOOK_SECRET
)
if (!isValid) {
return NextResponse.json({ error: 'Invalid' }, { status: 401 })
}
const event = JSON.parse(body)
switch (event.type) {
case 'payment.completed':
await fulfillOrder(event.data.orderId)
break
case 'payment.failed':
await notifyCustomer(event.data.customerId)
break
}
return NextResponse.json({ received: true })
}