A JavaScript client library for the x402 payment protocol. Wraps fetch() to handle HTTP 402 payment flows transparently.
import { x402Fetch } from 'bsv-x402'
const response = await x402Fetch('https://api.example.com/paid-endpoint')When the server responds with 402 Payment Required, the library:
- Parses the
X402-Challengeheader - Constructs a payment transaction via the browser wallet (BRC-100 /
window.CWI) - Broadcasts the transaction to the BSV network
- Retries the original request with an
X402-Proofheader
The app developer just uses x402Fetch in place of fetch. The browser wallet handles key management and signing.
npm install bsv-x402npm install # Install dependencies
npm run build # Compile TypeScript → dist/
npm test # Run tests
npm run typecheck # Type-check without emittingEarly development. The fetch wrapper and challenge parsing are in place; the BRC-100 wallet integration (constructProof) is not yet implemented.