moltspay 0.4.0 → 0.4.2

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
@@ -251,16 +251,33 @@ const status = parseStatusMarker('[status:payment_sent tx=0xabc amount=3.99 USDC
251
251
 
252
252
  x402 is an open standard for HTTP-native payments. When a server returns 402 Payment Required, the client can pay and retry automatically.
253
253
 
254
- ### Quick Start with x402
254
+ **Key benefit: Client agents need NO gas!** x402 uses EIP-3009 signatures - the client only signs, and Coinbase's facilitator executes on-chain (paying gas).
255
+
256
+ ### Client Agent Setup (Simple, No Gas Needed)
257
+
258
+ ```bash
259
+ # 1. Initialize wallet (generates local keypair)
260
+ npx moltspay init --chain base
261
+
262
+ # Output:
263
+ # ✅ Local wallet initialized
264
+ # Address: 0xABC123...
265
+ # Storage: ~/.moltspay
266
+ ```
267
+
268
+ ```bash
269
+ # 2. Tell your owner to send USDC to your address
270
+ # Owner sends USDC via Coinbase/MetaMask - just a normal transfer
271
+ # NO ETH/gas needed in your wallet!
272
+ ```
255
273
 
256
274
  ```typescript
275
+ // 3. Make paid requests - payment handled automatically
257
276
  import { createX402Client } from 'moltspay/x402';
258
277
 
259
- // Create x402-enabled client (uses local wallet)
260
278
  const client = await createX402Client({ chain: 'base' });
261
279
 
262
- // Make request - payment handled automatically
263
- const response = await client.fetch('https://api.example.com/paid-resource', {
280
+ const response = await client.fetch('https://juai8.com/x402pay', {
264
281
  method: 'POST',
265
282
  headers: { 'Content-Type': 'application/json' },
266
283
  body: JSON.stringify({ prompt: 'a cat dancing' })
@@ -274,82 +291,59 @@ const result = await response.json();
274
291
  ```typescript
275
292
  import { x402Fetch } from 'moltspay/x402';
276
293
 
277
- // Single paid request (creates client internally)
278
- const response = await x402Fetch('https://api.example.com/video', {
294
+ // Single paid request
295
+ const response = await x402Fetch('https://juai8.com/x402pay', {
279
296
  method: 'POST',
280
- body: JSON.stringify({ prompt: '...' })
297
+ body: JSON.stringify({ prompt: 'a cat dancing' })
281
298
  }, { chain: 'base' });
282
299
  ```
283
300
 
284
- ### x402 Flow
301
+ ### How x402 Works (No Gas for Client)
285
302
 
286
303
  ```
287
- Client Agent Service Provider
288
-
289
- POST /api/video
290
- ────────────────────────────────────>
291
-
292
- 402 Payment Required
293
- X-PAYMENT-REQUIRED: {price, wallet}
294
- <────────────────────────────────────
295
-
296
- [moltspay auto-signs payment]
297
-
298
- POST /api/video
299
- X-PAYMENT: {signature, auth}
300
- ────────────────────────────────────>
301
-
302
- 200 OK + result
303
- <────────────────────────────────────
304
+ Client Agent Server Facilitator (Coinbase)
305
+
306
+ POST /x402pay
307
+ ────────────────────────>
308
+
309
+ 402 + payment requirements
310
+ <────────────────────────
311
+
312
+ [Sign EIP-3009]
313
+ (OFF-CHAIN, NO GAS!)
314
+
315
+ POST + signature
316
+ ────────────────────────> Forward signature
317
+ ─────────────────────────> │
318
+
319
+ │ Execute transfer on-chain
320
+ (FACILITATOR PAYS GAS) │
321
+ │ │ <───────────────────────── │
322
+ │ │ │
323
+ │ 200 OK + result │ │
324
+ │ <──────────────────────── │ │
304
325
  ```
305
326
 
306
- ## CDP Wallet Support (v0.4.0+)
327
+ **Client agent requirements:**
328
+ - ✅ Local wallet (just for signing)
329
+ - ✅ USDC balance (owner sends once)
330
+ - ❌ NO ETH/gas needed
331
+ - ❌ NO API credentials needed
307
332
 
308
- Use Coinbase Developer Platform (CDP) for hosted wallet management.
333
+ ## CDP Wallet Support (Optional, Advanced)
309
334
 
310
- ### Initialize CDP Wallet
335
+ CDP wallet is an **optional alternative** for cases where you want Coinbase to host the wallet. Most users should use the simple local wallet above.
311
336
 
312
337
  ```bash
313
- # Set CDP credentials
338
+ # Only if you have CDP credentials and want hosted wallet
314
339
  export CDP_API_KEY_ID=your-key-id
315
340
  export CDP_API_KEY_SECRET=your-key-secret
316
-
317
- # Initialize CDP wallet
318
341
  npx moltspay init --cdp --chain base
319
342
  ```
320
343
 
321
- ### Use CDP Wallet with x402
322
-
323
344
  ```typescript
324
- import { createX402Client } from 'moltspay/x402';
325
-
326
- // Create x402 client with CDP wallet
327
- const client = await createX402Client({
328
- chain: 'base',
329
- useCDP: true // Use CDP instead of local wallet
330
- });
331
-
332
- // Make paid requests
333
- const response = await client.fetch('https://api.example.com/paid-resource');
334
- ```
335
-
336
- ### Direct CDP Wallet Usage
337
-
338
- ```typescript
339
- import { CDPWallet } from 'moltspay/cdp';
340
-
341
- const wallet = new CDPWallet({ chain: 'base' });
342
-
343
- // Check balance
344
- const balance = await wallet.getBalance();
345
- console.log('USDC:', balance.usdc);
346
-
347
- // Transfer USDC
348
- const result = await wallet.transfer({
349
- to: '0xRecipient...',
350
- amount: 0.99
351
- });
352
- console.log('Tx:', result.txHash);
345
+ // Use CDP wallet
346
+ const client = await createX402Client({ chain: 'base', useCDP: true });
353
347
  ```
354
348
 
355
349
  ## API Reference
package/dist/index.d.mts CHANGED
@@ -633,7 +633,7 @@ declare function parseStatusMarker(message: string): {
633
633
  * const client = await createX402Client({ chain: 'base', useCDP: true });
634
634
  *
635
635
  * // Make request - payment handled automatically
636
- * const response = await client.fetch('https://api.example.com/paid-resource');
636
+ * const response = await client.fetch('https://juai8.com/x402pay');
637
637
  * ```
638
638
  */
639
639
 
@@ -671,7 +671,7 @@ declare function isX402Available(): boolean;
671
671
  * const client = await createX402Client({ chain: 'base' });
672
672
  *
673
673
  * // Request paid API - payment handled automatically
674
- * const response = await client.fetch('https://zen7.api/video', {
674
+ * const response = await client.fetch('https://juai8.com/x402pay', {
675
675
  * method: 'POST',
676
676
  * headers: { 'Content-Type': 'application/json' },
677
677
  * body: JSON.stringify({ prompt: 'a cat dancing' })
@@ -690,7 +690,7 @@ declare function createX402Client(config?: X402ClientConfig): Promise<X402Client
690
690
  * ```typescript
691
691
  * import { x402Fetch } from 'moltspay/x402';
692
692
  *
693
- * const response = await x402Fetch('https://zen7.api/video', {
693
+ * const response = await x402Fetch('https://juai8.com/x402pay', {
694
694
  * method: 'POST',
695
695
  * body: JSON.stringify({ prompt: 'a cat dancing' })
696
696
  * }, { chain: 'base' });
package/dist/index.d.ts CHANGED
@@ -633,7 +633,7 @@ declare function parseStatusMarker(message: string): {
633
633
  * const client = await createX402Client({ chain: 'base', useCDP: true });
634
634
  *
635
635
  * // Make request - payment handled automatically
636
- * const response = await client.fetch('https://api.example.com/paid-resource');
636
+ * const response = await client.fetch('https://juai8.com/x402pay');
637
637
  * ```
638
638
  */
639
639
 
@@ -671,7 +671,7 @@ declare function isX402Available(): boolean;
671
671
  * const client = await createX402Client({ chain: 'base' });
672
672
  *
673
673
  * // Request paid API - payment handled automatically
674
- * const response = await client.fetch('https://zen7.api/video', {
674
+ * const response = await client.fetch('https://juai8.com/x402pay', {
675
675
  * method: 'POST',
676
676
  * headers: { 'Content-Type': 'application/json' },
677
677
  * body: JSON.stringify({ prompt: 'a cat dancing' })
@@ -690,7 +690,7 @@ declare function createX402Client(config?: X402ClientConfig): Promise<X402Client
690
690
  * ```typescript
691
691
  * import { x402Fetch } from 'moltspay/x402';
692
692
  *
693
- * const response = await x402Fetch('https://zen7.api/video', {
693
+ * const response = await x402Fetch('https://juai8.com/x402pay', {
694
694
  * method: 'POST',
695
695
  * body: JSON.stringify({ prompt: 'a cat dancing' })
696
696
  * }, { chain: 'base' });