> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Show a payment QR code

> Show a Solana Pay QR code for the order, confirm the payment onchain, and read the transfer the customer's wallet sends.

<div className="sol-stepper not-prose" data-path="checkout">
<div className="sol-stepper-nav" role="navigation" aria-label="Build a checkout · ~30 min">
<ol>
<li data-state="done"><a href="/developers/docs/payments/checkout/try-it"><span className="sol-stepper-n">Step 1<span className="sol-vh">, </span><span className="sol-stepper-done">Done</span><span className="sol-vh">: </span></span><span className="sol-stepper-t">Pay as a customer</span></a></li>
<li data-state="current"><a href="/developers/docs/payments/checkout/browser" aria-current="step"><span className="sol-stepper-n">Step 2<span className="sol-vh">: </span></span><span className="sol-stepper-t">Show a payment QR code</span></a></li>
<li data-state="todo"><a href="/developers/docs/payments/checkout/backend"><span className="sol-stepper-n">Step 3<span className="sol-vh">: </span></span><span className="sol-stepper-t">Confirm from your backend</span></a></li>
<li data-state="todo"><a href="/developers/docs/payments/checkout/go-live"><span className="sol-stepper-n">Step 4<span className="sol-vh">: </span></span><span className="sol-stepper-t">Go live</span></a></li>
</ol>
</div>
</div>

[Solana Pay](/developers/docs/tools/solana-pay) is the standard for payment
requests on Solana. Your checkout puts the order's recipient, amount, token, and
a unique reference into a
[transfer request](/developers/docs/tools/solana-pay/quickstart/transfer-requests)
URL and shows it as a QR code. The customer scans it, and their
<span className="sol-chip" data-concept="wallet"><Tooltip headline="Wallets & signatures" tip="A wallet holds a key pair: a public address that anyone can pay, and a private key that signs approvals and never leaves the device." cta="Learn more" href="/developers/docs/core/wallets">wallet</Tooltip><span className="nojs-only"> ([Wallets & signatures](/developers/docs/core/wallets): A wallet holds a key pair: a public address that anyone can pay, and a private key that signs approvals and never leaves the device.)</span></span> builds
the transfer, asks them to approve it, and sends it. Adding the QR code to your
own app is optional: the rest of the tutorial runs without it.

## Add the payment QR code

<Danger>
  `@solana/pay` is currently in beta. APIs may change before the stable
  release.
</Danger>

You need Node.js 20.18 or higher, a React or Next.js app (a fresh
`create-next-app` is fine), and a mobile wallet set to devnet. Fund it with
devnet USDC from the [Circle faucet](https://faucet.circle.com) and devnet SOL
from [faucet.solana.com](https://faucet.solana.com) to cover transaction fees.
Install Solana Pay:

```bash
npm install @solana/pay@beta @solana/kit@^6.5.0
```

The component creates a unique reference for the order, encodes it into a
transfer request URL, and renders the URL as a QR code. It then watches for a
transaction that includes the reference and validates the recipient, amount,
and token before marking the order paid. Set `MERCHANT_WALLET` to an address you
control:

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import {
  address,
  createSolanaRpc,
  createSolanaRpcSubscriptions,
  generateKeyPair,
  getAddressFromPublicKey
} from "@solana/kit";
import {
  createQR,
  encodeURL,
  validateTransfer,
  watchReference
} from "@solana/pay";

const MERCHANT_WALLET = address("your-wallet-address");
const USDC_DEVNET = address("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
const AMOUNT = 1;

const rpc = createSolanaRpc("https://api.devnet.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions(
  "wss://api.devnet.solana.com"
);

export function Checkout() {
  const qrRef = useRef<HTMLDivElement>(null);
  const [signature, setSignature] = useState<string | null>(null);

  useEffect(() => {
    const abortController = new AbortController();

    async function startPayment() {
      const keyPair = await generateKeyPair();
      const reference = await getAddressFromPublicKey(keyPair.publicKey);

      const url = encodeURL({
        recipient: MERCHANT_WALLET,
        amount: AMOUNT,
        splToken: USDC_DEVNET,
        reference,
        label: "My Store",
        message: "Order #1001"
      });

      if (abortController.signal.aborted) return;

      if (qrRef.current) {
        qrRef.current.innerHTML = "";
        createQR(url, 300).append(qrRef.current);
      }

      const result = await watchReference(rpcSubscriptions, reference, {
        abortSignal: abortController.signal
      });
      if (result.err) throw new Error("Payment transaction failed");

      await validateTransfer(rpc, result.signature, {
        recipient: MERCHANT_WALLET,
        amount: AMOUNT,
        splToken: USDC_DEVNET,
        reference
      });
      setSignature(result.signature);
    }

    startPayment().catch((error) => {
      if (!abortController.signal.aborted) console.error(error);
    });

    return () => abortController.abort();
  }, []);

  if (signature) return <p>Payment confirmed: {signature}</p>;
  return <div ref={qrRef} />;
}
```

`amount` is in token units, so `1` requests 1 USDC. Leave out `splToken` to
request SOL instead.

## Take a payment

Run your app, scan the QR code with your wallet, and approve the payment. Once
the
<span className="sol-chip" data-concept="transaction"><Tooltip headline="Transactions" tip="A transaction is a signed request to change the shared ledger. It either fully happens or doesn't happen at all, and once confirmed anyone can look it up." cta="Learn more" href="/developers/docs/core/transactions">transaction</Tooltip><span className="nojs-only"> ([Transactions](/developers/docs/core/transactions): A transaction is a signed request to change the shared ledger. It either fully happens or doesn't happen at all, and once confirmed anyone can look it up.)</span></span> confirms
and passes validation, the component shows the transaction signature. That signature is your receipt: look it up with
[getTransaction](/developers/docs/rpc/http/gettransaction) or in any explorer.

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Signatures</span> <span className="sol-concept-def">Every transaction is signed by the wallets it spends from.</span>](/developers/docs/core/transactions#signatures)
</div>

<Warning>
  **Don't ship orders from a browser check alone.** Validation in the browser
  is fine for a demo, but anything that runs in the browser can be faked. In
  the next step your server looks the signature up on the network and checks
  the amount, the recipient, and the order itself.
</Warning>

## The transfer the wallet sends

A USDC payment is one `TransferChecked` instruction: move this many base units
of this mint from the customer's
<span className="sol-chip" data-concept="token-account"><Tooltip headline="Token accounts" tip="Wallets don't hold tokens directly. Each token (USDC, or your own asset) gets a small account owned by the wallet, and transfers move between these accounts." cta="Learn more" href="/developers/docs/tokens/basics/create-token-account">USDC account</Tooltip><span className="nojs-only"> ([Token accounts](/developers/docs/tokens/basics/create-token-account): Wallets don't hold tokens directly. Each token (USDC, or your own asset) gets a small account owned by the wallet, and transfers move between these accounts.)</span></span> to
the store's. The wallet that scans the QR code builds it from the URL. Here's
the same payment with
[`@solana/kit`](/developers/docs/clients/official/javascript), the code behind step 1.
Like the wallet, it adds the order's reference as an extra read-only account,
following the
[Solana Pay reference](/developers/docs/tools/solana-pay/specification/version1-1#reference)
convention, so your server can match the payment to its order.

```ts checkout/pay.ts
import {
  AccountRole,
  appendTransactionMessageInstructions,
  assertIsTransactionWithBlockhashLifetime,
  createTransactionMessage,
  getSignatureFromTransaction,
  pipe,
  sendAndConfirmTransactionFactory,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
  signTransactionMessageWithSigners,
  type Address,
  type TransactionSigner,
} from "@solana/kit";
import {
  findAssociatedTokenPda,
  getTransferCheckedInstruction,
  TOKEN_PROGRAM_ADDRESS,
} from "@solana-program/token";
import { rpc, rpcSubscriptions, USDC_DECIMALS, USDC_MINT } from "./config";

const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
  rpc,
  rpcSubscriptions,
});

/**
 * The customer pays `amount` USDC base units (1 USDC = 1_000_000) to the
 * store's USDC token account. `reference` is a fresh address for this order,
 * added as a read-only account so the backend can tell which order a
 * transaction pays for (the Solana Pay convention).
 */
export async function payStore(
  customer: TransactionSigner,
  order: { storeOwner: Address; amount: bigint; reference: Address },
) {
  const [source] = await findAssociatedTokenPda({
    owner: customer.address,
    mint: USDC_MINT,
    tokenProgram: TOKEN_PROGRAM_ADDRESS,
  });
  const [destination] = await findAssociatedTokenPda({
    owner: order.storeOwner,
    mint: USDC_MINT,
    tokenProgram: TOKEN_PROGRAM_ADDRESS,
  });

  const transfer = getTransferCheckedInstruction({
    source,
    mint: USDC_MINT,
    destination,
    authority: customer,
    amount: order.amount,
    decimals: USDC_DECIMALS,
  });
  const transferWithReference = {
    ...transfer,
    accounts: [
      ...transfer.accounts,
      { address: order.reference, role: AccountRole.READONLY },
    ],
  };

  const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
  const message = pipe(
    createTransactionMessage({ version: 0 }),
    (m) => setTransactionMessageFeePayerSigner(customer, m),
    (m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
    (m) => appendTransactionMessageInstructions([transferWithReference], m),
  );
  const transaction = await signTransactionMessageWithSigners(message);
  assertIsTransactionWithBlockhashLifetime(transaction);
  await sendAndConfirmTransaction(transaction, { commitment: "confirmed" });
  return getSignatureFromTransaction(transaction);
}
```

<div className="sol-term not-prose" data-term="paths/payments/checkout/pay" data-tab="checkout/pay.ts" data-kind="block" data-steps="1" data-l-run="Run" data-l-run-step="Run step" data-l-next="Next step" data-l-all="Run all" data-l-again="Run again" data-l-running="Running…" data-l-tx="Sending transaction…" data-l-http="Requesting…" data-l-call="Running…" data-l-confirming="Confirming…" data-l-done="Done" data-l-copied="Copied" data-l-step="Step">
<div className="sol-term-head"><span className="sol-term-title">What Node prints for the order and the signature payStore() returns, on a local test network (Surfpool)</span><span className="sol-term-env">Local test network (Surfpool)</span><button type="button" className="sol-term-copy" data-act="copy">Copy</button></div>
<div className="sol-term-screen" role="region" tabIndex="0" aria-label="What Node prints for the order and the signature payStore() returns, on a local test network (Surfpool): Output">
<div className="sol-term-step" data-step="1" data-pending="tx">
<div className="sol-term-row sol-term-cmd"><span className="sol-term-ps" aria-hidden="true">\></span> order</div>
<div className="sol-term-row sol-term-ln">\{</div>
<div className="sol-term-row sol-term-ln" data-indent="2"><span className="sol-term-k">id\:</span> `'order-1001',`</div>
<div className="sol-term-row sol-term-ln" data-indent="2"><span className="sol-term-k">storeOwner\:</span> `'`<span className="sol-h" title="DVxMtF9M6EAQ8CjqH9omYUTXdJU7hu4M8G94udRyr1m6"><span className="sol-h-f">DVxMtF9M6EAQ8CjqH9omYUTXdJU7hu4M8G94udRyr1m6</span><span className="sol-h-s" aria-hidden="true">DVxM…r1m6</span></span>`',`</div>
<div className="sol-term-row sol-term-ln" data-indent="2"><span className="sol-term-k">amount\:</span> 1000000n,</div>
<div className="sol-term-row sol-term-ln" data-indent="2"><span className="sol-term-k">reference\:</span> `'`<span className="sol-h" title="47venn787GZLWUcgUU3QM1CpT11JHQMs8hyYQMPXKN2W"><span className="sol-h-f">47venn787GZLWUcgUU3QM1CpT11JHQMs8hyYQMPXKN2W</span><span className="sol-h-s" aria-hidden="true">47ve…KN2W</span></span>`'`</div>
<div className="sol-term-row sol-term-ln">\}</div>
<div className="sol-term-row sol-term-cmd"><span className="sol-term-ps" aria-hidden="true">\></span> const signature = await payStore(customer, order)</div>
<div className="sol-term-row sol-term-cmd"><span className="sol-term-ps" aria-hidden="true">\></span> signature</div>
<div className="sol-term-row sol-term-ln">`'`<span className="sol-h" title="paxK3zbseZEZpGrmGrzm3p3VYF5XN6aTAGKS1sVt2CmkcJ2afLCTB5C84rFT8VFX6LboNFty2pzcTCiVJw5DAtJ"><span className="sol-h-f">paxK3zbseZEZpGrmGrzm3p3VYF5XN6aTAGKS1sVt2CmkcJ2afLCTB5C84rFT8VFX6LboNFty2pzcTCiVJw5DAtJ</span><span className="sol-h-s" aria-hidden="true">paxK…DAtJ</span></span>`'`</div>
<div className="sol-term-result"><span className="sol-term-badge" data-tone="info">Payment sent · not verified yet</span></div>
</div>
</div>
<div className="sol-term-foot"><button type="button" className="sol-term-btn" data-act="run">Run</button><span className="sol-term-status"></span><span className="sol-term-sr" role="status"></span></div>
</div>

The rest of the tutorial uses this code. Call `payStore` from your checkout when
the customer pays from a wallet connected to your app rather than by scanning a
QR code: it takes the customer's signer and the order, and works in any
frontend or on a server.
