Charge for HTTP content
The mpp-proxy ↗ template is a Cloudflare Worker that sits in front of any HTTP backend. When a request hits a protected route, the proxy returns a 402 response with an MPP payment challenge. After the client pays, the proxy verifies the payment, forwards the request to your origin, and issues a 1-hour session cookie.
Deploy the mpp-proxy template to your Cloudflare account:
- A Cloudflare account ↗
- An HTTP backend to gate
- A wallet address to receive payments
Define protected routes in wrangler.jsonc:
{ "vars": { "PAY_TO": "0xYourWalletAddress", "TEMPO_TESTNET": false, "PAYMENT_CURRENCY": "0x20c000000000000000000000b9537d11c60e8b50", "PROTECTED_PATTERNS": [ { "pattern": "/premium/*", "amount": "0.01", "description": "Access to premium content for 1 hour" } ] }}With Bot Management, the proxy can charge crawlers while keeping the site free for humans:
{ "pattern": "/content/*", "amount": "0.25", "description": "Content access for 1 hour", "bot_score_threshold": 30, "except_detection_ids": [120623194, 117479730]}Requests with a bot score at or below bot_score_threshold are directed to the paywall. Use except_detection_ids to allowlist specific crawlers by detection ID.
Clone the template, edit wrangler.jsonc, and deploy:
git clone https://github.com/cloudflare/mpp-proxycd mpp-proxynpm installnpx wrangler secret put JWT_SECRETnpx wrangler secret put MPP_SECRET_KEYnpx wrangler deployFor full configuration options, proxy modes, and Bot Management examples, refer to the mpp-proxy README ↗.
For more control, add MPP middleware directly to your Worker using Hono:
import { Hono } from "hono";import { Mppx, tempo } from "mppx/hono";
const app = new Hono();
const mppx = Mppx.create({ methods: [ tempo({ currency: "0x20c0000000000000000000000000000000000000", recipient: "0xYourWalletAddress", }), ],});
app.get("/premium", mppx.charge({ amount: "0.10" }), (c) => c.json({ data: "Thanks for paying!" }),);
export default app;Refer to the Hono middleware reference ↗ for the full API, including session payments and payer identification.
- mpp.dev ↗ — Protocol specification
- Pay Per Crawl — Cloudflare-native monetization without custom code