x402 icon indicating copy to clipboard operation
x402 copied to clipboard

feat: Extract paywall; refactor for v2 spec

Open apmcdermott opened this issue 2 months ago • 1 comments

Extracts the paywall from the monolithic legacy package into a standalone @x402/paywall package with modular architecture, builder pattern API, and tree-shakeable network-specific imports.

New Package: @x402/paywall

Location: typescript/packages/http/paywall/

Key Features:

  • Standalone paywall package with EVM and Solana support
  • Builder pattern for flexible configuration
  • Subpath exports for tree shaking: /evm and /svm
  • Backwards compatible with legacy x402/paywall API

Bundle Sizes:

  • Full paywall: 3.5 MB (both networks)
  • EVM only: 3.4 MB (probably due to OnchainKit... we should figure out a way to reduce this)
  • Solana only: 1.0 MB

Core Integration

@x402/core:

  • Added PaywallProvider interface
  • Added setPaywallProvider() method to x402HTTPResourceService
  • Auto-detects and uses @x402/paywall if installed, otherwise falls back to basic HTML

@x402/express:

  • Added optional PaywallProvider parameter to paymentMiddleware()

Architecture

@x402/paywall (main)
├── index.ts          - Legacy getPaywallHtml() + builder exports
├── builder.ts        - PaywallBuilder with withNetwork() and withConfig()
├── types.ts          - PaywallProvider, PaywallNetworkHandler interfaces
├── evm/
│   ├── index.ts      - evmPaywall handler
│   ├── EvmPaywall.tsx
│   └── build.ts      - Separate build for EVM-only bundle
└── svm/
    ├── index.ts      - svmPaywall handler
    ├── SolanaPaywall.tsx
    └── build.ts      - Separate build for Solana-only bundle

API

Builder Pattern

import { createPaywall } from '@x402/paywall';
import { evmPaywall } from '@x402/paywall/evm';

const paywall = createPaywall()
  .withNetwork(evmPaywall)
  .withConfig({ appName: 'My App', testnet: true })
  .build();

app.use(paymentMiddleware(routes, facs, schemes, undefined, paywall));

Network-Specific Imports

// EVM only - no Solana dependencies
import { evmPaywall } from '@x402/paywall/evm';

// Solana only - no EVM dependencies
import { svmPaywall } from '@x402/paywall/svm';

Checklist

  • [x] I have formatted and linted my code
  • [ ] All new and existing tests pass
  • [x] My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits

apmcdermott avatar Nov 04 '25 22:11 apmcdermott

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
x402 Ready Ready Preview Comment Nov 12, 2025 0:26am

vercel[bot] avatar Nov 04 '25 22:11 vercel[bot]