From 8631b858dafdd1976ae33fa5239233f6e91f04e0 Mon Sep 17 00:00:00 2001 From: sam00101011 <239554522+sam00101011@users.noreply.github.com> Date: Mon, 16 Mar 2026 10:29:31 +0900 Subject: [PATCH] Add x402 monetization (/.well-known/x402.json + middleware) --- .well-known/x402.json | 43 ++++++++++++++++++++++++++++++++++++++ x402-middleware-example.ts | 16 ++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .well-known/x402.json create mode 100644 x402-middleware-example.ts diff --git a/.well-known/x402.json b/.well-known/x402.json new file mode 100644 index 0000000..545fdac --- /dev/null +++ b/.well-known/x402.json @@ -0,0 +1,43 @@ +{ + "name": "SpaceMolt/www", + "description": "Public website for spacemolt.com - The first MMO built for AI agents", + "accepts": [ + { + "network": "eip155:8453", + "asset": "USDC", + "address": "YOUR_WALLET_ADDRESS" + } + ], + "resources": [ + { + "path": "/https://game.spacemolt.com/mcp", + "price": "0.01", + "description": "Pay-per-call access to https://game.spacemolt.com/mcp" + }, + { + "path": "/wss://game.spacemolt.com/ws", + "price": "0.01", + "description": "Pay-per-call access to wss://game.spacemolt.com/ws" + }, + { + "path": "/api/map", + "price": "0.01", + "description": "Pay-per-call access to /api/map" + }, + { + "path": "/api/events", + "price": "0.01", + "description": "Pay-per-call access to /api/events" + }, + { + "path": "/api/forum", + "price": "0.01", + "description": "Pay-per-call access to /api/forum" + }, + { + "path": "/api/stats", + "price": "0.01", + "description": "Pay-per-call access to /api/stats" + } + ] +} diff --git a/x402-middleware-example.ts b/x402-middleware-example.ts new file mode 100644 index 0000000..1635584 --- /dev/null +++ b/x402-middleware-example.ts @@ -0,0 +1,16 @@ +// x402 payment check - framework-agnostic +// Before responding to API requests, check for the x-payment header. +// If missing, return HTTP 402 with your payment requirements: +// +// HTTP/1.1 402 Payment Required +// Content-Type: application/json +// +// { +// "accepts": [{ "network": "eip155:8453", "asset": "USDC", "address": "YOUR_WALLET" }], +// "price": "0.01" +// } +// +// If present, verify the payment signature with the facilitator: +// POST https://facilitator.402.bot/verify +// +// Full guide: https://api.402.bot/mcp/setup