Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

I built a paywall that can't be bypassed with DevTools

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 boo

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:

  1. Payment verification β€” reading the chain, not trusting the client.
  2. Entitlement storage β€” who has a key, stored in KV.
  3. 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":"[email protected]"}
β†’ { "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:

  1. GET /v1/transactions/{txid}/events β€” find the Transfer event for the USDT contract.
  2. Convert the event's hex addresses to Tron base58 (0x41 prefix + double-SHA-256 checksum + base58).
  3. Divide the raw value by 10^6.
  4. Cross-check GET /v1/transactions/{txid} for contractRet === 'SUCCESS'.
  5. Compare against the expected recipient and minimum amount.
  6. 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.

Try it

Feedback welcome β€” especially on whether you would actually pay with the unique-amount flow or prefer x402.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.