{"id":49868900,"url":"https://github.com/fuseio/fuse402","last_synced_at":"2026-05-15T04:07:59.799Z","repository":{"id":354163667,"uuid":"1218967752","full_name":"fuseio/fuse402","owner":"fuseio","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-13T12:52:57.000Z","size":153,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-13T14:32:51.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://fuse402.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fuseio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-23T11:53:44.000Z","updated_at":"2026-05-13T12:53:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fuseio/fuse402","commit_stats":null,"previous_names":["fuseio/fuse402"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fuseio/fuse402","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuseio%2Ffuse402","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuseio%2Ffuse402/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuseio%2Ffuse402/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuseio%2Ffuse402/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fuseio","download_url":"https://codeload.github.com/fuseio/fuse402/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuseio%2Ffuse402/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33053180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-15T04:07:59.009Z","updated_at":"2026-05-15T04:07:59.779Z","avatar_url":"https://github.com/fuseio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fuse402 — Fuse Network Business Payments \u0026 Loyalty API\n\nPay-per-request access to Fuse Network blockchain data and business payment\ninfrastructure. The same endpoints accept payment over **two protocols**\nsimultaneously:\n\n- **x402** — USDC on Base via the [x402 protocol](https://x402.org), settled\n  by the Coinbase CDP facilitator. Payable from any x402 client, including\n  the [Solid Agent Wallet](https://solid.xyz) and the\n  [Coinbase Agentic Wallet](https://docs.cdp.coinbase.com/agentic-wallet/welcome).\n- **MPP** ([Machine Payments Protocol](https://mpp.dev), co-authored by Tempo\n  and Stripe) — three rails on one wire:\n  - **Tempo** USDC (stablecoin, sub-second finality on Tempo mainnet `4217` /\n    Moderato testnet `42431`)\n  - **Stripe** — Visa, Mastercard, and digital wallets via Stripe Shared\n    Payment Tokens\n  - **Bitcoin Lightning** via [Spark](https://www.buildonspark.com/)\n\nBoth protocols cohabit a single 402 response: x402 clients read\n`X-PAYMENT-REQUIRED`, MPP clients read `WWW-Authenticate: Payment` (one entry\nper method). See [src/middleware/dual-pay.ts](src/middleware/dual-pay.ts) for\nthe dispatch + composite-challenge logic.\n\n## Live Deployment\n\n- **URL**: https://ai.fuse.io\n- **x402 settlement**: Base mainnet (eip155:8453), USDC\n- **MPP settlement**: Tempo (testnet by default), Stripe (USD), Lightning (BTC)\n- **Data network**: Fuse mainnet (chain 122) via [explorer.fuse.io](https://explorer.fuse.io) Blockscout + viem\n\n## Endpoints\n\n| Method | Path | Price | Description |\n| --- | --- | --- | --- |\n| GET | `/api/fuse/stats` | $0.01 | Real-time Fuse network statistics from Blockscout. |\n| GET | `/api/fuse/wallet/:address` | $0.05 | Balance, tx count, token-transfer count, last activity for any Fuse wallet. |\n| GET | `/api/fuse/defi/opportunities` | $0.10 | Live Fuse-chain DeFi products (DefiLlama TVL + Solid.xyz APY windows). |\n| POST | `/api/fuse/loyalty/create` | $5.00 | Deploys a real `LoyaltyToken` ERC-20 (mintable, burnable, owner + minter ACL) on Fuse via viem. **Caller is the owner.** |\n| POST | `/api/fuse/loyalty/mint` | $0.50 | Mints additional units of an existing `LoyaltyToken` (requires the deployer still holds the minter role). |\n| GET | `/api/fuse/loyalty/balance/:token/:address` | $0.02 | Reads any Fuse ERC-20 balance via viem. |\n\nFree routes:\n\n- `GET /health` — health check\n- `GET /openapi.json` — OpenAPI 3.1.0 spec. Each paid operation carries:\n  - `x-payment-info.price` + `x-payment-info.protocols` (x402scan-flavored)\n  - `x-payment-info.offers[]` — one entry per MPP method (tempo / stripe / lightning) so MPP-aware agents can pre-select before issuing the request\n- `GET /.well-known/x402` — well-known v1 discovery fallback\n\nDocument root also exposes `x-service-info` (categories + docs links) per the\nMPP discovery spec.\n\n### Loyalty token custody\n\n`/loyalty/create` deploys a token on the caller's behalf:\n\n- The caller's `owner` address (passed in the request body) becomes the\n  on-chain owner and receives the initial supply.\n- This service's deployer wallet is seeded as an initial **minter** so\n  `/loyalty/mint` works out of the box.\n- The owner can revoke the server's mint privilege at any time by calling\n  `setMinter(deployerAddress, false)` on the token contract. After that,\n  `/loyalty/mint` will revert for that token.\n\nThis service never holds the owner role and cannot transfer ownership,\npause, or burn caller-owned tokens.\n\n## Tech stack\n\n- TypeScript on Node 20+ (run with [`tsx`](https://github.com/privatenumber/tsx))\n- [express](https://expressjs.com/) 5.x\n- x402 path: [@x402/express](https://www.npmjs.com/package/@x402/express),\n  [@x402/core](https://www.npmjs.com/package/@x402/core),\n  [@coinbase/x402](https://www.npmjs.com/package/@coinbase/x402)\n- MPP path: [mppx](https://www.npmjs.com/package/mppx) (wevm),\n  [stripe](https://www.npmjs.com/package/stripe),\n  [@buildonspark/lightning-mpp-sdk](https://www.npmjs.com/package/@buildonspark/lightning-mpp-sdk)\n- [viem](https://viem.sh) — Fuse RPC + ERC-20 reads/writes + contract deployment\n- [zod](https://zod.dev) — request validation\n- Blockscout REST API at `explorer.fuse.io`, DefiLlama, Solid Analytics\n\n## Local development\n\n1. Copy `.env.example` to `.env` and fill in the required values.\n\n   **x402 (always required):**\n   - `PAY_TO_WALLET` — wallet that receives x402 USDC payments on Base.\n   - `CDP_API_KEY_ID` / `CDP_API_KEY_SECRET` — Coinbase CDP credentials (https://portal.cdp.coinbase.com).\n   - `DEPLOYER_PRIVATE_KEY` — Fuse-mainnet EOA used to deploy loyalty tokens and mint on the caller's behalf. Needs a small FUSE balance for gas.\n\n   **MPP (required when `MPP_ENABLED=true`, which is the default):**\n   - `MPP_SECRET_KEY` — HMAC key binding challenge IDs to contents. Generate once with `node -e \"console.log(require('crypto').randomBytes(32).toString('base64'))\"`. Treat as root-of-trust.\n   - `TEMPO_PAY_TO` — recipient address on Tempo (testnet Moderato or mainnet, selected by `TEMPO_TESTNET`).\n   - `STRIPE_SECRET_KEY` — `sk_test_…` for development, `sk_live_…` in prod. Stripe account must have machine payments enabled.\n   - `STRIPE_NETWORK_ID` — Business Network profile ID from the Stripe Dashboard.\n   - `BTC_MNEMONIC` — server-side Spark wallet seed for Lightning. Use `BTC_NETWORK=regtest` for local dev (free), `signet` for public testnet, `mainnet` for real BTC.\n\n   To ship MPP code dark, set `MPP_ENABLED=false` — all MPP env vars become\n   optional and the server runs in x402-only mode (current production behavior).\n\n2. Install + run:\n\n   ```bash\n   pnpm install\n   pnpm dev          # tsx watch\n   pnpm test         # patches/extensions-forward smoke test\n   pnpm build        # tsc --noEmit (typecheck only)\n   ```\n\n`pnpm start` runs the same TypeScript entry under `tsx` without a build\nstep.\n\n## Funding wallets\n\n**x402 (Base USDC)** — fund `PAY_TO_WALLET` with USDC on Base for receiving;\nno inbound funding needed (clients pay you).\n\n**Tempo testnet (Moderato, chain 42431)** — get free test stablecoins\n(pathUSD / AlphaUSD / BetaUSD / ThetaUSD) for any address at\n[docs.tempo.xyz/quickstart/faucet](https://docs.tempo.xyz/quickstart/faucet).\n\n**Tempo mainnet (chain 4217)** — bridge USDC from Ethereum / Base / Arbitrum\n/ Optimism / Polygon via [relay.link/bridge](https://relay.link/bridge). The\ndefault mainnet token is USDC.e at `0x20C000000000000000000000b9537d11c60E8b50`.\n\n**Stripe** — no wallet, payments land directly in the connected Stripe\naccount.\n\n**Lightning** — for testing, use the Spark testnet faucet; for production,\nthe server's Spark wallet (seeded by `BTC_MNEMONIC`) needs no inbound balance\nsince each payment generates a fresh BOLT11 invoice paid by the client.\n\n## Deployment\n\nDeployed on Vercel behind the `ai.fuse.io` custom domain. Configure all\nsecrets as Vercel environment variables for the Production environment —\nnothing is hardcoded in `vercel.json`.\n\nEntry point: `src/index.ts` (compiled by `@vercel/node`).\n\n## Usage\n\n### x402 client\n\nEach protected route returns a 402 challenge until a valid `X-PAYMENT`\nheader is presented. Example with `curl`:\n\n```bash\ncurl -i https://ai.fuse.io/api/fuse/stats\n```\n\nFor real consumption use a wallet-aware client such as the\n[Solid Agent Wallet](https://solid.xyz) or the\n[Coinbase Agentic Wallet](https://docs.cdp.coinbase.com/agentic-wallet/welcome) —\nboth sign the 402 challenge and resend automatically, settling in USDC on Base.\n\n### MPP client\n\nMPP clients read the `WWW-Authenticate: Payment …` headers on the 402, pick\na method, sign a credential, and resend with `Authorization: Payment …`. The\n[`mppx`](https://www.npmjs.com/package/mppx) CLI does this automatically:\n\n```bash\nnpx mppx pay https://ai.fuse.io/api/fuse/stats\n```\n\nDiscovery: agents can fetch `/openapi.json` and pre-select a method from\n`x-payment-info.offers[]` before issuing the request, avoiding the\nchallenge round-trip.\n\n## Architecture\n\n```\n                ┌──────────────────────────────────┐\n   request ───▶│  src/middleware/dual-pay.ts       │\n                │                                   │\n                │  ┌─ Authorization: Payment        │\n                │  │   → mpp.compose() verify       │\n                │  │   → req.__mppPaid = true       │\n                │  │                                │\n                │  ├─ X-PAYMENT                     │\n                │  │   → next() (let x402 run)      │\n                │  │                                │\n                │  └─ (no creds)                    │\n                │      → pre-build MPP challenges,  │\n                │        hook res.writeHead to add  │\n                │        WWW-Authenticate on 402    │\n                └─────────────┬────────────────────┘\n                              │ next()\n                              ▼\n                ┌──────────────────────────────────┐\n                │  @x402/express paymentMiddleware │\n                │  (skipped if __mppPaid)          │\n                └─────────────┬────────────────────┘\n                              │ paid?\n                              ▼\n                ┌──────────────────────────────────┐\n                │  route handler (stats / wallet / │\n                │  defi / loyalty.*)               │\n                └──────────────────────────────────┘\n```\n\nSingle source of truth for the route → price table lives in\n[`PAID_ROUTES`](src/index.ts) at the top of `src/index.ts`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuseio%2Ffuse402","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuseio%2Ffuse402","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuseio%2Ffuse402/lists"}