
Public
Likex402-playground
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v64View latest version
A demo app showing how to use the x402 protocol (HTTP 402 payments) to pay for a Browserbase browser session and take website screenshots — all powered by automatic USDC micropayments on Base.
Rendering mermaid diagram...
- The user enters a URL and submits the screenshot form
- The app calls
x402.browserbase.comto create a paid browser session - The
@x402/fetchSDK transparently handles the HTTP 402 flow — it parses the payment requirements, signs a USDC transfer on Base (EIP-3009), and retries the request with aPAYMENT-SIGNATUREheader - Browserbase returns a WebSocket URL for a remote Chromium instance
- The app connects via Playwright, navigates to the target URL, and returns a PNG screenshot
- The transaction is recorded in SQLite for the history page
buyer.tsx → HTTP entry point (Hono router)
routes/
home.tsx → Landing page with wallet info & navigation
screenshot.tsx → Screenshot form + POST handler
transactions.tsx → Transaction history table
lib/
x402.ts → x402 client setup (wallet signer + wrapFetchWithPayment)
browserbase.ts → Browserbase session creation via x402
screenshot.ts → Playwright CDP screenshot capture
db.ts → SQLite schema & queries for transaction log
layout.tsx → Shared HTML layout with Twind CSS
| Key | Description |
|---|---|
X402_PRIVATE_KEY | Private key for a Base wallet holding USDC (used to sign x402 payments) |
| Route | Description |
|---|---|
/ | Home — shows wallet address, explains the flow, links to other pages |
/screenshot | Form to enter a URL and capture a screenshot ($0.01 USDC per session) |
/transactions | Table of past payments with totals and tx hashes |