I built a paywall that can't be bypassed with DevTools (Cloudflare Workers + KV + USDT-TRC20)
A client-side paywall is a suggestion, not a paywall. If the check runs in the browser, anyone can open DevTools, flip a boolean, and unlock your "Pro" features. I wanted to see what a real crypto paywall looks like without a billing account, a backend server, or KYC — so I built one with Cloudflare Workers, KV, and Tron's USDT-TRC20.
Live service: https://proofgate.proofgate.workers.dev
Source: https://github.com/alexcompute123nab-debug/proofgate
The rule I started with
Every access decision must be made on a machine I control, using data an attacker cannot forge locally.
That means three things have to live in the Worker:
- Payment verification — reading the chain, not trusting the client.
- Entitlement storage — who has a key, stored in KV.
- Replay protection — the same transaction cannot unlock two accounts.
The browser only ever sends a transaction hash and reads a JSON verdict.
Matching an anonymous on-chain transfer to a customer
TRC20 transfers have no memo field. If you ask someone to "send 10 USDT and paste the txid", you cannot tell which customer paid — two people can send the same amount at the same time.
The trick I used: a unique cent amount per order.
POST /v1/order {"email":"buyer@example.com"}
→ { "order_id": "24035bd3b4fcf7c0",
"amount": 10.998245,
"to": "TM2deFM4byG1rVvhA15fTJD7gLaE9xvSid" }
The amount is derived from sha256(order_id + email), so it is unique per order. The customer sends exactly that amount. The Worker scans the treasury's incoming TRC20 transfers and looks for a transfer whose value matches the order's raw amount (6 decimals):
const expectedRaw = String(Math.round(order.unique_amount * 1e6));
const hit = transfers.find(t =>
t.to === TREASURY &&
t.token_info?.symbol === 'USDT' &&
String(t.value) === expectedRaw
);
if (!hit) return json({ status: 'pending' });
Only when that matches does the Worker generate an API key, store its SHA-256 in KV, and return it to the client.
Verifying a payment server-side
Given a txid, the Worker calls TronGrid:
-
GET /v1/transactions/{txid}/events— find theTransferevent for the USDT contract. - Convert the event's hex addresses to Tron base58 (0x41 prefix + double-SHA-256 checksum + base58).
- Divide the raw
valueby 10^6. - Cross-check
GET /v1/transactions/{txid}forcontractRet === 'SUCCESS'. - Compare against the expected recipient and minimum amount.
- Write the txid to KV as "used" (30-day TTL) so it cannot be replayed.
A real response from the deployed service:
{
"verified": true,
"from": "TNS6Nk6sLT2ahajCsGyi8QxD3rQhsF7QLU",
"to": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"amount": 15,
"success": true,
"block": 88228145,
"checked_by": "proofgate-worker"
}
Two bugs I hit deploying it
1. KV binding in ES modules. I wrote PROOF_KV.get(...) and got PROOF_KV is not defined. In an ES-module Worker the binding arrives via the env parameter, so the handler must do const KV = env.PROOF_KV and pass it down.
2. workers.dev subdomain. wrangler deploy said success but the URL failed TLS with ERR_SSL_VERSION_OR_CIPHER_MISMATCH. The account had no registered subdomain yet — I had to register it in the dashboard and redeploy. Lesson: a green deploy is not a working endpoint. Always curl /health.
What this does not solve
- The claim scan reads the last 50 incoming transfers. A high-volume treasury needs an indexed event feed.
- "Verified" means public chain evidence, not chargeback protection.
- Unique-amount matching is clever but awkward UX. A proper x402 flow would be cleaner — that is the next iteration I want to try.
What is free and what is not
The public inspector is for manual checks only: five lookups per IP per day, in the browser. It has no API key, no widget, no webhooks and no replay protection, so it is not for accepting payments. The 10 USDT lifetime key is what enables /v1/verify with replay protection in KV, the embeddable widget with status polling, webhooks and 5,000 calls a day.
Acceptable use
ProofGate must not be used for fraud, phishing or unlawful activity. A key may be revoked without refund on an abuse report. Reports go to the abuse contact in the API reference or GitHub Issues.
Theme and embedding
The site has a light and dark toggle in the header. It follows the system preference until you choose, then remembers the choice. The embeddable widget accepts data-theme (auto, light or dark), data-accent for a brand hex colour and data-label for the button text. All three go in the script tag.
Try it
- Live API + docs: https://proofgate.proofgate.workers.dev
- Source (MIT): https://github.com/alexcompute123nab-debug/proofgate
Feedback welcome — especially on whether you would actually pay with the unique-amount flow or prefer x402.
Top comments (0)