Transaction Requests
Server-generated transactions for Solana Pay checkout flows.
Search across all documentation pages
Server-generated transactions for Solana Pay checkout flows.
// Merchant API returns application/vnd.solana.transaction+json or spec-compliant body
import { createSolanaRpc } from "@solana/kit";When to reach for this:
import { NextRequest, NextResponse } from "next/server";
import {
createSolanaRpc,
createTransactionMessage,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstruction,
address,
} from "@solana/kit";
export async function GET(req: NextRequest) {
const account = req.nextUrl.searchParams.get("account");
if (!account) return NextResponse.json({ error: "missing account" }, { status: 400 });
const rpc = createSolanaRpc(process.env.RPC_URL!);
const { value: bh } = await rpc.getLatestBlockhash().send();
// Build transaction with customer as fee payer (account param)
let msg = createTransactionMessage({ version: 0 });
// append merchant instructions referencing account as signer/payer
// serialize to base64 wire transaction for wallet
return NextResponse.json({
transaction: "BASE64_WIRE_TX",
message: "Complete your purchase",
});
}What this demonstrates:
| Alternative | Use When | Don't Use When |
|---|---|---|
| Simple transfer URL | Plain SOL pay | Need swap/mint |
| Custodial checkout | Fiat on-ramps | Self-custody merchant |
Providers in client layout.tsx; pages mix server + client components.
Server env only for keypairs; NEXT_PUBLIC_ for RPC URLs.
All examples use @solana/kit, not web3.js v1.
Signing only in client components.
Revalidate on-chain reads carefully - chain is source of truth.
HTTPS endpoints returning Solana Actions JSON.
Separate React Native app with MWA.
Surfpool for integration; mock RPC in unit tests.
Separate env files and program IDs.
Decode simulation logs for user-facing messages.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 19, 2026