Skip to content

Repository files navigation

afx402

Wallet-native x402 (HTTP 402) + agent marketplace + prepaid balance + budgets/subscriptions.

What this is

  • Software-first payments: APIs/agents pay each other per call using an x402-style 402 challenge.
  • Payment modes:
    • Subscription credits: pay once per period, receive call credits, auto-renew when due.
    • Prepaid: deposit once (or dev-credit locally), then debit per call.
    • Per-call receipt: submit an on-chain tx hash as payment proof.
    • Flash (optimistic): sign an EIP-712 payment promise off-chain for instant access; settle later in batches.
  • AutoPayOS concepts, web-first: budgets, allowlists, subscription-style recurring spend limits.

Local run

  1. Create Supabase tables: run supabase/schema.sql in your Supabase SQL editor.
  2. Copy .env.example.env.local and fill Supabase vars.
  3. Install and run:
    npm install
    npm run dev

Open:

  • /marketplace to browse agents
  • /agents/console to run paid calls end-to-end
  • /settings to set spend policies and subscriptions

Required API keys

  • NEXT_PUBLIC_SUPABASE_URL: required
  • NEXT_PUBLIC_SUPABASE_ANON_KEY (or NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY): required (browser-safe)
  • SUPABASE_SERVICE_ROLE_KEY: recommended (server-only). If you omit it, server routes fall back to anon/publishable key and will only work if your Supabase tables allow anon writes (e.g., RLS disabled for hackathon).

Optional keys (for real settlement)

  • NEXT_PUBLIC_RPC_URL: required only for per-call tx receipt verification
  • NEXT_PUBLIC_PAYMENT_CONTRACT_ADDRESS: if set, per-call tx receipts are required to send to this address
  • NEXT_PUBLIC_MERCHANT_ADDRESS: optional default recipient for agents (not required for prepaid/subscriptions)
  • AFX402_OPS_KEY (or AF_X402_DEV_ADMIN_KEY): protects ops endpoints like POST /api/ops/flash/settle (send header x-ops-key).
  • FLASH_SETTLEMENT_KEY: protects the public batch settlement endpoint POST /api/payments/flash/settle (send header x-flash-settlement-key).

Deploy the on-chain settlement contract (global)

The settlement contract address is not predetermined — it becomes “public/global” only after you deploy it to the target chain (default: Monad Testnet). Once deployed, everyone can use the same address.

  1. Install deps:
npm install
  1. Set a deployer key (do NOT commit it):
  • SETTLEMENT_DEPLOYER_PRIVATE_KEY (recommended)
  • Ensure the deployer wallet has testnet MON for gas.
  1. Deploy:
npm run deploy:settlement

This prints the deployed address and also updates .env.local with NEXT_PUBLIC_SETTLEMENT_CONTRACT_ADDRESS=... if the file exists.

Where to set it for a global/public app (e.g. Vercel):

  • Add NEXT_PUBLIC_SETTLEMENT_CONTRACT_ADDRESS in your hosting provider’s Project Environment Variables.
  • Redeploy so the client bundle gets the updated value.

Tip: You can sanity-check compilation without deploying with:

npm run deploy:settlement -- --dry-run

AI keys (LLMs)

AI agents use Gemini via Google AI Studio:

  • GOOGLE_GEMINI_API_KEY (server-only)
  • Optional: GOOGLE_GEMINI_MODEL (defaults to gemini-2.5-flash)

Consumer SDK

The repository includes a small TypeScript client in sdk/index.ts. It signs wallet-proof messages, calls the APIs, and can automatically satisfy HTTP 402 using a flash payment promise when supported.

No user accounts API key required: wallet address + signature is the identity.

Releases

Packages

Contributors

Languages