PaidOnChain

Accept USDC payments in Next.js on Base

This is the pattern: show the buyer your address and price, they pay from any wallet, they paste (or your frontend submits) the tx hash, and a server route verifies it before fulfilling the order.

1. Install

npm install github:orja12/paidonchain

2. Server route: app/api/claim/route.js

import { verifyPayment } from "paidonchain";
import { db } from "@/lib/db"; // your database

const PAY_TO = process.env.PAY_TO; // your receiving address

export async function POST(req) {
  const { orderId, tx } = await req.json();
  const order = await db.order.findUnique({ where: { id: orderId } });
  if (!order || order.paid) return Response.json({ error: "invalid order" }, { status: 400 });

  // replay protection: one tx can only ever pay one order
  if (await db.order.findFirst({ where: { txHash: tx.toLowerCase() } }))
    return Response.json({ error: "tx already used" }, { status: 409 });

  const r = await verifyPayment({ chain: "base", tx, to: PAY_TO, minAmount: order.priceUsdc });
  if (!r.ok) return Response.json(r, { status: r.code === "PENDING" ? 202 : 402 });

  await db.order.update({ where: { id: orderId }, data: { paid: true, txHash: tx.toLowerCase(), payer: r.from } });
  return Response.json({ ok: true });
}
import { paymentURI } from "paidonchain";
const uri = paymentURI({ chain: "base", to: PAY_TO, amount: order.priceUsdc });
// render as a QR code; MetaMask, Coinbase Wallet and Rainbow open it directly

Gotchas

More guides