/** * x402's three lines, paid with px402. * * node --env-file=.env three-lines.js * * .env holds PX402_PRIVATE_KEY, and nothing else: on Base the issuer, the * registry and the bridge facilitator default to PRXVT's hosted ones. * The key's address holds USDC, and nothing else; the wallet deposits from * it (gaslessly: a relayer pays the gas for a fee taken out of the deposit), * withdraws, waits out the hold, and pays -- a px402 merchant directly, an * `exact` one through the bridge. */ import { wrapFetchWithPayment } from "px402"; import { keyFromEnv } from "./drop-in.js"; // A 0x private key, or an account: a viem local account is one. const account = keyFromEnv("PX402_PRIVATE_KEY"); const pay = wrapFetchWithPayment(fetch, account); const res = await pay(process.argv[2] ?? "https://api.example.com/data"); console.log(`${String(res.status)} ${await res.text()}`);