x402-mantle-sdk 0.1.0

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 ADDED
@@ -0,0 +1,130 @@
1
+ # @x402-devkit/sdk
2
+
3
+ Complete SDK for x402 paid APIs on Mantle Network. Monetize your APIs with HTTP 402 payments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @x402-devkit/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Server - Protect API Routes
14
+
15
+ ```typescript
16
+ import { Hono } from 'hono'
17
+ import { x402 } from '@x402-devkit/sdk/server'
18
+
19
+ const app = new Hono()
20
+
21
+ // Protect route with payment (0.001 MNT)
22
+ app.use('/api/premium', x402({
23
+ price: '0.001',
24
+ token: 'MNT',
25
+ testnet: true // Use mantle-sepolia for testing
26
+ }))
27
+
28
+ app.get('/api/premium', (c) => {
29
+ return c.json({ data: 'Premium content' })
30
+ })
31
+ ```
32
+
33
+ ### Client - Handle Payments
34
+
35
+ ```typescript
36
+ import { x402Fetch } from '@x402-devkit/sdk/client'
37
+
38
+ // Automatically handles 402 responses with payment modal
39
+ const response = await x402Fetch('https://api.example.com/api/premium')
40
+ const data = await response.json()
41
+ ```
42
+
43
+ ### React - Payment Modal Component
44
+
45
+ ```tsx
46
+ import { PaymentModal } from '@x402-devkit/sdk/client/react'
47
+
48
+ function App() {
49
+ const [isOpen, setIsOpen] = useState(false)
50
+ const [request, setRequest] = useState(null)
51
+
52
+ return (
53
+ <PaymentModal
54
+ request={request}
55
+ isOpen={isOpen}
56
+ onComplete={(payment) => {
57
+ console.log('Paid:', payment.transactionHash)
58
+ setIsOpen(false)
59
+ }}
60
+ onCancel={() => setIsOpen(false)}
61
+ />
62
+ )
63
+ }
64
+ ```
65
+
66
+ ## Features
67
+
68
+ - **Server Middleware**: Hono middleware for payment-gated routes
69
+ - **Client SDK**: Automatic 402 handling with wallet integration
70
+ - **React Components**: Ready-to-use payment modal
71
+ - **Mantle Network**: Native support for Mantle mainnet and testnet
72
+ - **Multiple Tokens**: Support for MNT, USDC, USDT, mETH, WMNT
73
+ - **Custom Networks**: Register custom networks and tokens
74
+ - **0.5% Platform Fee**: Automatic fee splitting to Treasury
75
+
76
+ ## Environment Variables
77
+
78
+ ### Server
79
+ ```env
80
+ X402_APP_ID=your-app-id
81
+ X402_PLATFORM_URL=https://api.x402.dev # Optional
82
+ ```
83
+
84
+ ## Networks
85
+
86
+ | Network | Chain ID | Token |
87
+ |---------|----------|-------|
88
+ | Mantle Mainnet | 5000 | MNT |
89
+ | Mantle Sepolia | 5003 | MNT |
90
+
91
+ ## API Reference
92
+
93
+ ### Server Exports
94
+
95
+ ```typescript
96
+ import {
97
+ x402, // Main middleware
98
+ verifyPayment, // Manual payment verification
99
+ getNetworkConfig, // Get network configuration
100
+ registerCustomNetwork, // Register custom network
101
+ } from '@x402-devkit/sdk/server'
102
+ ```
103
+
104
+ ### Client Exports
105
+
106
+ ```typescript
107
+ import {
108
+ x402Fetch, // Enhanced fetch with 402 handling
109
+ x402Client, // Client factory
110
+ connectWallet, // Connect wallet
111
+ processPayment, // Process payment manually
112
+ TREASURY_ADDRESS, // Treasury contract address
113
+ } from '@x402-devkit/sdk/client'
114
+ ```
115
+
116
+ ### React Exports
117
+
118
+ ```typescript
119
+ import { PaymentModal } from '@x402-devkit/sdk/client/react'
120
+ ```
121
+
122
+ ## Treasury
123
+
124
+ Platform fee (0.5%) is automatically sent to the Treasury contract:
125
+ - **Address**: `0xB27705342ACE73736AE490540Ea031cc06C3eF49`
126
+ - **Network**: Mantle Sepolia
127
+
128
+ ## License
129
+
130
+ MIT