x402-mantle-sdk 0.2.3 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,31 +1,61 @@
1
- # @x402-devkit/sdk
1
+ # x402-mantle-sdk
2
2
 
3
- > Complete SDK for monetizing APIs with HTTP 402 payments on Mantle Network
3
+ Complete SDK for monetizing APIs with HTTP 402 payments on Mantle Network
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/@x402-devkit/sdk)](https://www.npmjs.com/package/@x402-devkit/sdk)
5
+ [![npm version](https://img.shields.io/npm/v/x402-mantle-sdk)](https://www.npmjs.com/package/x402-mantle-sdk)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
  [![Mantle Network](https://img.shields.io/badge/Network-Mantle-blue)](https://mantle.xyz)
8
8
 
9
- **@x402-devkit/sdk** enables developers to monetize APIs using HTTP 402 Payment Required status code with blockchain payments on Mantle Network. Protect your API routes, handle payments automatically, and track revenue—all with a few lines of code.
9
+ **x402-mantle-sdk** enables developers to monetize APIs using HTTP 402 Payment Required status code with blockchain payments on Mantle Network. Protect your API routes, handle payments automatically, and track revenue—all with a few lines of code.
10
10
 
11
- ## Features
11
+ ## Features
12
12
 
13
- - 🚀 **Zero-Configuration Setup** - Get started in minutes
14
- - 💰 **Automatic Payment Handling** - Seamless wallet integration
15
- - 📊 **Real-Time Analytics** - Track endpoint usage and revenue
16
- - 🔒 **Blockchain Verification** - On-chain payment validation
17
- - 🎨 **Beautiful UI Components** - Ready-to-use React payment modals
18
- - 🌐 **Multi-Token Support** - MNT, USDC, USDT, mETH, WMNT
19
- - **Ultra-Low Fees** - Gas costs under $0.001 on Mantle
20
- - 🔄 **Auto Endpoint Tracking** - Endpoints appear in dashboard automatically
13
+ - **Zero-Configuration Setup** - Get started in minutes
14
+ - **Automatic Payment Handling** - Seamless wallet integration
15
+ - **Real-Time Analytics** - Track endpoint usage and revenue
16
+ - **Blockchain Verification** - On-chain payment validation
17
+ - **UI Components** - Ready-to-use React payment modals
18
+ - **Multi-Token Support** - MNT, USDC, USDT, mETH, WMNT
19
+ - **Ultra-Low Fees** - Gas costs under $0.001 on Mantle
20
+ - **Auto Endpoint Tracking** - Endpoints appear in dashboard automatically
21
21
 
22
- ## 📦 Installation
22
+ ## Installation
23
23
 
24
24
  ```bash
25
- npm install @x402-devkit/sdk
25
+ npm install x402-mantle-sdk
26
26
  ```
27
27
 
28
- ## 🚀 Quick Start
28
+ ## Quick Start
29
+
30
+ ### Option 1: Use the CLI (Recommended)
31
+
32
+ The fastest way to get started is using the `create-x402-app` CLI tool:
33
+
34
+ ```bash
35
+ npx create-x402-app my-api
36
+ cd my-api
37
+ npm run dev
38
+ ```
39
+
40
+ This creates a fully configured project with:
41
+ - Example API routes (free and paid)
42
+ - Wallet connection UI
43
+ - Payment modal integration
44
+ - TypeScript configuration
45
+
46
+ The CLI provides 4 templates:
47
+ - `backend-hono` - Standalone Hono API server
48
+ - `backend-express` - Standalone Express API server
49
+ - `fullstack-hono` - Next.js app with Hono API routes
50
+ - `fullstack-express` - Next.js app with Express-style API routes
51
+
52
+ ### Option 2: Manual Installation
53
+
54
+ If you prefer to set up manually:
55
+
56
+ ```bash
57
+ npm install x402-mantle-sdk
58
+ ```
29
59
 
30
60
  ### 1. Create a Project
31
61
 
@@ -35,7 +65,7 @@ Visit the [x402 Dashboard](https://mantle-x402.vercel.app/dashboard) to create a
35
65
 
36
66
  ```typescript
37
67
  import { Hono } from 'hono'
38
- import { x402 } from '@x402-devkit/sdk/server'
68
+ import { x402 } from 'x402-mantle-sdk/server'
39
69
 
40
70
  const app = new Hono()
41
71
 
@@ -57,23 +87,23 @@ app.get('/api/premium', (c) => {
57
87
  ### 3. Handle Payments on Client
58
88
 
59
89
  ```typescript
60
- import { x402Fetch } from '@x402-devkit/sdk/client'
90
+ import { x402Fetch } from 'x402-mantle-sdk/client'
61
91
 
62
92
  // Automatically handles 402 responses with payment modal
63
93
  const response = await x402Fetch('https://api.example.com/api/premium')
64
94
  const data = await response.json()
65
95
  ```
66
96
 
67
- **That's it!** Your API now accepts blockchain payments. 🎉
97
+ That's it! Your API now accepts blockchain payments.
68
98
 
69
- ## 📖 Documentation
99
+ ## Documentation
70
100
 
71
101
  ### Server Usage
72
102
 
73
103
  #### Basic Middleware
74
104
 
75
105
  ```typescript
76
- import { x402 } from '@x402-devkit/sdk/server'
106
+ import { x402 } from 'x402-mantle-sdk/server'
77
107
 
78
108
  app.use('/api/data', x402({
79
109
  price: '0.001',
@@ -110,7 +140,7 @@ X402_PLATFORM_URL=https://mantle-x402.vercel.app
110
140
  #### Automatic Payment Handling
111
141
 
112
142
  ```typescript
113
- import { x402Fetch } from '@x402-devkit/sdk/client'
143
+ import { x402Fetch } from 'x402-mantle-sdk/client'
114
144
 
115
145
  // Automatically intercepts 402 responses and shows payment modal
116
146
  const response = await x402Fetch('https://api.example.com/api/premium')
@@ -120,14 +150,15 @@ const data = await response.json()
120
150
  #### Custom Client Configuration
121
151
 
122
152
  ```typescript
123
- import { x402Client } from '@x402-devkit/sdk/client'
153
+ import { X402Client } from 'x402-mantle-sdk/client'
124
154
 
125
- const client = x402Client({
155
+ const client = new X402Client({
126
156
  autoRetry: true,
127
157
  autoSwitchNetwork: true,
128
158
  testnet: false
129
159
  })
130
160
 
161
+ await client.initialize()
131
162
  const response = await client.fetch('https://api.example.com/api/premium')
132
163
  ```
133
164
 
@@ -136,7 +167,7 @@ const response = await client.fetch('https://api.example.com/api/premium')
136
167
  #### Basic Payment Modal
137
168
 
138
169
  ```tsx
139
- import { PaymentModal } from '@x402-devkit/sdk/client/react'
170
+ import { PaymentModal } from 'x402-mantle-sdk/client/react'
140
171
 
141
172
  function App() {
142
173
  const [isOpen, setIsOpen] = useState(false)
@@ -159,7 +190,7 @@ function App() {
159
190
  #### Enhanced Payment Modal
160
191
 
161
192
  ```tsx
162
- import { EnhancedPaymentModal } from '@x402-devkit/sdk/client/react'
193
+ import { EnhancedPaymentModal } from 'x402-mantle-sdk/client/react'
163
194
 
164
195
  function App() {
165
196
  const [isOpen, setIsOpen] = useState(false)
@@ -189,14 +220,14 @@ function App() {
189
220
  }
190
221
  ```
191
222
 
192
- ## 🌐 Supported Networks
223
+ ## Supported Networks
193
224
 
194
225
  | Network | Chain ID | Status | Tokens |
195
226
  |---------|----------|--------|--------|
196
- | Mantle Mainnet | 5000 | Production | MNT, USDC, USDT, mETH, WMNT |
197
- | Mantle Sepolia | 5003 | Testnet | MNT, USDC, mETH, WMNT |
227
+ | Mantle Mainnet | 5000 | Production | MNT, USDC, USDT, mETH, WMNT |
228
+ | Mantle Sepolia | 5003 | Testnet | MNT, USDC, mETH, WMNT |
198
229
 
199
- ## 💡 Use Cases
230
+ ## Use Cases
200
231
 
201
232
  - **AI & LLM APIs** - Charge per token, per request, or per compute second
202
233
  - **Data APIs** - Monetize datasets, market data, or proprietary information
@@ -204,7 +235,7 @@ function App() {
204
235
  - **Premium Content** - Articles, research, analysis with micropayments
205
236
  - **IoT & Sensors** - Sell real-time sensor data with pay-per-read
206
237
 
207
- ## 📊 Dashboard & Analytics
238
+ ## Dashboard & Analytics
208
239
 
209
240
  All endpoints are automatically tracked in the [x402 Dashboard](https://mantle-x402.vercel.app/dashboard):
210
241
 
@@ -213,7 +244,7 @@ All endpoints are automatically tracked in the [x402 Dashboard](https://mantle-x
213
244
  - **Revenue Analytics** - Track earnings per endpoint
214
245
  - **Usage Statistics** - Monitor API usage patterns
215
246
 
216
- ## 🔧 API Reference
247
+ ## API Reference
217
248
 
218
249
  ### Server Exports
219
250
 
@@ -221,10 +252,13 @@ All endpoints are automatically tracked in the [x402 Dashboard](https://mantle-x
221
252
  import {
222
253
  // Main middleware
223
254
  x402,
255
+ x402Express,
256
+ processPaymentMiddleware,
224
257
 
225
258
  // Payment verification
226
259
  verifyPayment,
227
260
  verifyPaymentOnChain,
261
+ extractPaymentReceipt,
228
262
 
229
263
  // Network utilities
230
264
  getNetworkConfig,
@@ -232,14 +266,11 @@ import {
232
266
  registerCustomNetwork,
233
267
  registerCustomTokens,
234
268
 
235
- // Analytics
236
- logPayment,
237
- registerEndpoint,
238
-
239
269
  // Platform
240
270
  initializePlatform,
241
271
  getProjectConfig,
242
- } from '@x402-devkit/sdk/server'
272
+ clearCache,
273
+ } from 'x402-mantle-sdk/server'
243
274
  ```
244
275
 
245
276
  ### Client Exports
@@ -248,7 +279,7 @@ import {
248
279
  import {
249
280
  // Fetch with 402 handling
250
281
  x402Fetch,
251
- x402Client,
282
+ X402Client,
252
283
 
253
284
  // Wallet utilities
254
285
  connectWallet,
@@ -258,10 +289,13 @@ import {
258
289
  // Payment processing
259
290
  processPayment,
260
291
 
292
+ // Payment modal
293
+ createVanillaPaymentModal,
294
+
261
295
  // Constants
262
296
  TREASURY_ADDRESS,
263
297
  PLATFORM_FEE_BPS,
264
- } from '@x402-devkit/sdk/client'
298
+ } from 'x402-mantle-sdk/client'
265
299
  ```
266
300
 
267
301
  ### React Exports
@@ -270,56 +304,61 @@ import {
270
304
  import {
271
305
  PaymentModal, // Basic payment modal
272
306
  EnhancedPaymentModal, // Enhanced modal with success states
273
- } from '@x402-devkit/sdk/client/react'
307
+ } from 'x402-mantle-sdk/client/react'
274
308
  ```
275
309
 
276
- ## 🏗️ Architecture
310
+ ## Architecture
277
311
 
278
312
  ```
279
- @x402-devkit/sdk
313
+ x402-mantle-sdk
280
314
  ├── /server # Server middleware (Hono, Express-compatible)
281
315
  ├── /client # Client SDK (fetch, wallet integration)
282
316
  └── /client/react # React components (payment modals)
283
317
  ```
284
318
 
285
- ## 🔐 Security
319
+ ## Related Packages
320
+
321
+ - **x402-mantle-sdk** - Core SDK package (this package)
322
+ - **create-x402-app** - CLI tool for scaffolding projects
323
+ - Install: `npx create-x402-app my-app`
324
+ - Creates ready-to-use starter templates with examples
325
+ - [View on npm](https://www.npmjs.com/package/create-x402-app)
326
+
327
+ ## Security
286
328
 
287
329
  - **On-Chain Verification** - All payments verified on blockchain
288
330
  - **No Private Keys** - Wallet-based payments only
289
331
  - **Idempotent Payments** - Duplicate transaction protection
290
332
  - **Amount Tolerance** - Handles minor blockchain rounding
291
333
 
292
- ## 💰 Pricing & Fees
334
+ ## Pricing & Fees
293
335
 
294
336
  - **Platform Fee**: 0.5% (automatically split to Treasury)
295
337
  - **Gas Costs**: < $0.001 per transaction on Mantle
296
338
  - **No Hidden Fees**: Transparent fee structure
297
339
 
298
- ## 🤝 Contributing
340
+ ## Contributing
299
341
 
300
342
  Contributions are welcome! Please read our contributing guidelines first.
301
343
 
302
- ## 📄 License
344
+ ## License
303
345
 
304
346
  MIT License - see [LICENSE](LICENSE) file for details.
305
347
 
306
- ## 🔗 Links
348
+ ## Links
307
349
 
308
350
  - **Dashboard**: [https://mantle-x402.vercel.app](https://mantle-x402.vercel.app)
309
351
  - **Documentation**: [https://mantle-x402.vercel.app/dashboard?tab=docs](https://mantle-x402.vercel.app/dashboard?tab=docs)
310
- - **GitHub**: [https://github.com/x402-devkit/x402](https://github.com/x402-devkit/x402)
352
+ - **GitHub**: [https://github.com/Debanjannnn/x-402-mantle-sdk](https://github.com/Debanjannnn/x-402-mantle-sdk)
311
353
  - **Mantle Network**: [https://mantle.xyz](https://mantle.xyz)
354
+ - **npm Package**: [https://www.npmjs.com/package/x402-mantle-sdk](https://www.npmjs.com/package/x402-mantle-sdk)
312
355
 
313
- ## 🆘 Support
356
+ ## Support
314
357
 
315
- - **Issues**: [GitHub Issues](https://github.com/x402-devkit/x402/issues)
358
+ - **Issues**: [GitHub Issues](https://github.com/Debanjannnn/x-402-mantle-sdk/issues)
316
359
  - **Discord**: [Join our community](https://discord.gg/x402)
317
360
  - **Email**: support@x402.dev
318
361
 
319
- ## 🙏 Acknowledgments
362
+ ## Acknowledgments
320
363
 
321
364
  Built for [Mantle Network](https://mantle.xyz) - the fastest and cheapest Layer 2 for Ethereum.
322
-
323
- ---
324
-
325
- **Made with ❤️ for the Mantle ecosystem**
@@ -354,6 +354,7 @@ async function processPayment(request, wallet) {
354
354
 
355
355
  // src/client/modal-react.tsx
356
356
  var import_jsx_runtime = require("react/jsx-runtime");
357
+ var DEFAULT_LOGO = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 120'%3E%3Cdefs%3E%3ClinearGradient id='bg' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' style='stop-color:%231a1a2e'/%3E%3Cstop offset='100%25' style='stop-color:%230f0f1a'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='120' height='120' rx='24' fill='url(%23bg)'/%3E%3Crect x='4' y='4' width='112' height='112' rx='20' fill='none' stroke='%23ffffff15' stroke-width='1'/%3E%3Ctext x='60' y='72' text-anchor='middle' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif' font-size='32' font-weight='600' fill='%23ffffff'%3Ex402%3C/text%3E%3C/svg%3E`;
357
358
  function formatAddress(address) {
358
359
  if (!address || typeof address !== "string") {
359
360
  return "N/A";
@@ -363,7 +364,7 @@ function formatAddress(address) {
363
364
  }
364
365
  return `${address.slice(0, 6)}...${address.slice(-4)}`;
365
366
  }
366
- function PaymentModal({ request, onComplete, onCancel, isOpen }) {
367
+ function PaymentModal({ request, onComplete, onCancel, isOpen, logo, logoAlt = "x402" }) {
367
368
  const [walletAddress, setWalletAddress] = (0, import_react.useState)(null);
368
369
  const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
369
370
  const [isProcessing, setIsProcessing] = (0, import_react.useState)(false);
@@ -541,21 +542,16 @@ function PaymentModal({ request, onComplete, onCancel, isOpen }) {
541
542
  children: [
542
543
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
543
544
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
544
- "div",
545
+ "img",
545
546
  {
547
+ src: logo || DEFAULT_LOGO,
548
+ alt: logoAlt,
546
549
  style: {
547
550
  width: "2rem",
548
551
  height: "2rem",
549
- display: "flex",
550
- alignItems: "center",
551
- justifyContent: "center",
552
552
  borderRadius: "0.5rem",
553
- background: "rgba(255, 255, 255, 0.1)",
554
- fontFamily: "monospace",
555
- fontSize: "0.75rem",
556
- fontWeight: "bold"
557
- },
558
- children: "x402"
553
+ objectFit: "contain"
554
+ }
559
555
  }
560
556
  ),
561
557
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { style: { margin: 0, fontSize: "1.25rem", fontWeight: 300 }, children: "Payment Required" })