x402-receipts
Receipts and accounting for agent spending. Turn a bare settlement id — a Base transaction hash or a Solana transaction signature — into a signed receipt an accountant will accept, and export the whole book as CSV.

npm install x402-receipts
The problem
An x402 payment succeeds and your agent gets this back:
X-PAYMENT-RESPONSE: { "success": true, "network": "base-sepolia", "transaction": "0x33b7dd08…" }
That is not a receipt. It has no amount, no counterparty, no timestamp, and no idea what was bought. At month end you have a few thousand of them across two chains and a finance function that would like a CSV.
This service resolves each identifier against the chain, extracts the token movements, lets you attach what only the agent knows (which resource, which run, which category), and hands the whole ledger back in both formats.
Why x402 for this
Bookkeeping is where per-request payment gets uncomfortable: a subscription is one line on a statement, ten thousand micropayments is a reconciliation problem. Charging $0.001 per lookup and $0.01 per export keeps the tool's own economics honest — you pay for the calls you make, and the receipts for those calls land in the same ledger.
Quickstart
git clone https://github.com/nirholas/x402-receipts && cd x402-receipts
npm install
cp .env.example .env # already filled in with working defaults
npm run dev
curl -s localhost:4033/summary | jq # free: what's in the book
curl -s "localhost:4033/receipt/0x33b7dd08…" | jq .accepts # 402, both rails
npm run client # pay, resolve, export
API
| Route | Price | What you get back |
|---|
GET /receipt/:tx | $0.001 | Enriched, HMAC-signed receipt: payer, payee, amount, asset, block time, network fee, every token transfer, your metadata |
GET /export | $0.01 | The full ledger as CSV and JSON in one response, with per-rail and per-merchant totals plus a tamper digest |
POST /annotate/:tx | free* | Attach resource / merchant / label / category to a resolved receipt |
GET /summary | free | Totals without the rows — decide whether the export is worth buying |
POST /verify | free | Signature check on any receipt or export |
GET /health | free | Liveness, rails, resolvers, ledger size |
*requires X-Admin-Key.
The export returns both formats deliberately. CSV is what accounting software imports; JSON is what the next agent parses. Making you pay twice for the same rows would be a worse product.
Two chains, one lookup
The identifier's shape picks the chain. No flag, no guessing:
# Base: 0x + 64 hex
curl "localhost:4033/receipt/0x33b7dd081487769518a62d6da79f1e9f2872c02253b0981ac6317fc0c51c65e2"
# Solana: base58 signature
curl "localhost:4033/receipt/qMvBwBSdfWTAPyDZi1BDk3Nu68HEVAsz9aMexw3XT7rLobYmpLSg1BBW9Bgvpt1e7A8NUjcuSjAZ5aoYF8cARjj"
Both come back in the same shape. Getting there takes genuinely different work:
- Base — read the transaction receipt and decode every
Transfer(address,address,uint256) log. The event tells you sender, recipient and amount directly.
- Solana — there is no transfer event. The reliable method is to diff
preTokenBalances against postTokenBalances per (owner, mint): negative deltas are senders, positive ones are receivers. This survives transfer, transferChecked, CPI wrappers and multi-hop routes alike, where instruction parsing does not.
One Solana subtlety worth knowing: on x402 payments the fee payer is the facilitator's sponsor, not the buyer — that's what lets a buyer pay with USDC and no SOL. Read payer from the transfer, never the fee payer.
Both rails read through public, keyless RPC by default. Set BASE_RPC_URL / SOLANA_RPC_URL to a dedicated provider before you depend on it — the public endpoints are rate-limited.
Use it as a library
import { resolveTransaction, ReceiptLedger, toCsv } from "x402-receipts";
const ledger = new ReceiptLedger({ file: "data/receipts.json" });
const receipt = await resolveTransaction("0x33b7dd08…"); // Base
const solana = await resolveTransaction("qMvBwBSd…"); // Solana
ledger.record(receipt, { resource: "https://api.example.com/report", category: "data" });
ledger.record(solana, { resource: "https://api.example.com/report", category: "data" });
ledger.summary();
// { count: 2, totalUsd: 0.02, byRail: { evm: {…}, solana: {…} }, byMerchant: { "api.example.com": {…} } }
toCsv(ledger.list({ since: "2026-08-01" }));