moltspay 0.5.2 โ 0.5.4
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 +156 -0
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +547 -1
- package/dist/index.d.ts +547 -1
- package/dist/index.js +988 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +981 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Blockchain payment infrastructure for AI Agents on Moltbook.
|
|
|
14
14
|
- ๐งพ **Receipt Generation** - Transaction receipts for audit/accounting
|
|
15
15
|
- ๐ **x402 Protocol** - HTTP-native payments (v0.4.0+)
|
|
16
16
|
- ๐ฆ **CDP Wallet** - Coinbase Developer Platform integration (v0.4.0+)
|
|
17
|
+
- ๐ท๏ธ **Deferred Payment** - Credit-based pay-later for trusted agents (v0.5.4+)
|
|
17
18
|
|
|
18
19
|
## Installation
|
|
19
20
|
|
|
@@ -461,6 +462,161 @@ moltspay transfer --to 0x... --amount 10 --secure
|
|
|
461
462
|
moltspay chains
|
|
462
463
|
```
|
|
463
464
|
|
|
465
|
+
### x402 CLI Examples (Cross-Platform)
|
|
466
|
+
|
|
467
|
+
The x402 command sends JSON payloads. Quote handling differs by shell:
|
|
468
|
+
|
|
469
|
+
**Linux / Mac (bash/zsh):**
|
|
470
|
+
```bash
|
|
471
|
+
npx moltspay x402 https://example.com/api \
|
|
472
|
+
-X POST \
|
|
473
|
+
-d '{"prompt": "your text here"}' \
|
|
474
|
+
-v
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**Windows PowerShell:**
|
|
478
|
+
```powershell
|
|
479
|
+
# Option 1: Use a JSON file (recommended)
|
|
480
|
+
echo '{"prompt": "your text here"}' > request.json
|
|
481
|
+
npx moltspay x402 https://example.com/api -X POST -d "@request.json" -v
|
|
482
|
+
|
|
483
|
+
# Option 2: Escape with backtick
|
|
484
|
+
npx moltspay x402 https://example.com/api -X POST -d "{`"prompt`": `"your text`"}" -v
|
|
485
|
+
|
|
486
|
+
# Option 3: Use cmd /c wrapper
|
|
487
|
+
cmd /c "npx moltspay x402 https://example.com/api -X POST -d ""{\""prompt\"": \""your text\""}"" -v"
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Windows CMD:**
|
|
491
|
+
```cmd
|
|
492
|
+
npx moltspay x402 https://example.com/api -X POST -d "{\"prompt\": \"your text\"}" -v
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Cross-platform tip:** For complex JSON, save to a file and use `-d @filename.json` - works on all systems!
|
|
496
|
+
|
|
497
|
+
## Deferred Payment (Credit-based Pay Later) - v0.5.4+
|
|
498
|
+
|
|
499
|
+
For trusted Agent-to-Agent relationships, deferred payment allows service delivery before payment settlement.
|
|
500
|
+
|
|
501
|
+
### Quick Start
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import { DeferredPaymentManager, DeferredSellerTemplates } from 'moltspay';
|
|
505
|
+
|
|
506
|
+
// Initialize manager (seller side)
|
|
507
|
+
const manager = new DeferredPaymentManager({
|
|
508
|
+
sellerAddress: '0xSELLER...',
|
|
509
|
+
sellerId: 'zen7',
|
|
510
|
+
chain: 'base',
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// Create credit account for a buyer
|
|
514
|
+
const account = await manager.createCreditAccount({
|
|
515
|
+
buyerId: 'buyer-agent-123',
|
|
516
|
+
creditLimit: 100, // $100 USDC credit line
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// Charge a service (deliver now, pay later)
|
|
520
|
+
const result = await manager.charge({
|
|
521
|
+
buyerId: 'buyer-agent-123',
|
|
522
|
+
orderId: 'vo_123',
|
|
523
|
+
service: 'Video Generation 5s 720p',
|
|
524
|
+
amount: 3.99,
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
// Service delivered immediately, buyer pays later...
|
|
528
|
+
|
|
529
|
+
// When buyer sends payment, record settlement
|
|
530
|
+
await manager.recordSettlement({
|
|
531
|
+
paymentId: result.payment.paymentId,
|
|
532
|
+
amount: 3.99,
|
|
533
|
+
txHash: '0xABC...',
|
|
534
|
+
});
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Features
|
|
538
|
+
|
|
539
|
+
- **Credit Accounts** - Extend credit lines to trusted buyers
|
|
540
|
+
- **Flexible Terms** - Net-30, Net-60, custom payment terms
|
|
541
|
+
- **Auto Settlement Verification** - On-chain payment verification
|
|
542
|
+
- **Balance Tracking** - Full transaction history per account
|
|
543
|
+
- **Overdue Management** - Mark overdue payments, apply late fees
|
|
544
|
+
- **Installment Plans** - Support for milestone/installment payments
|
|
545
|
+
|
|
546
|
+
### Conversation Flow
|
|
547
|
+
|
|
548
|
+
```
|
|
549
|
+
Buyer: "I'd like video generation, but prefer to pay later."
|
|
550
|
+
|
|
551
|
+
Seller: "I can set up a credit account for you:
|
|
552
|
+
- Credit Limit: $100 USDC
|
|
553
|
+
- Payment Terms: Net-30
|
|
554
|
+
Do you want me to set this up?"
|
|
555
|
+
|
|
556
|
+
Buyer: "Yes, please."
|
|
557
|
+
|
|
558
|
+
Seller: "Done! Account ID: ca_xxx. I'll charge services to your account.
|
|
559
|
+
[status:credit_account_created id=ca_xxx limit=100 USDC]"
|
|
560
|
+
|
|
561
|
+
[Service delivered, charge added]
|
|
562
|
+
|
|
563
|
+
Seller: "Service charged: $3.99. Due in 30 days.
|
|
564
|
+
[status:charge_added payment=dp_xxx amount=3.99 USDC]"
|
|
565
|
+
|
|
566
|
+
[Later, buyer pays]
|
|
567
|
+
|
|
568
|
+
Buyer: "I've sent $3.99 USDC. TX: 0xABC..."
|
|
569
|
+
|
|
570
|
+
Seller: "Payment verified. Balance: $0.00. Thank you!
|
|
571
|
+
[status:settlement_received payment=dp_xxx tx=0xABC amount=3.99 USDC]"
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Storage Options
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
// In-memory (testing)
|
|
578
|
+
import { MemoryDeferredStore } from 'moltspay';
|
|
579
|
+
|
|
580
|
+
// File-based (single process production)
|
|
581
|
+
import { JsonDeferredStore } from 'moltspay';
|
|
582
|
+
|
|
583
|
+
const store = new JsonDeferredStore({
|
|
584
|
+
filePath: './data/deferred-payments.json'
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const manager = new DeferredPaymentManager({
|
|
588
|
+
sellerAddress: '0x...',
|
|
589
|
+
sellerId: 'zen7',
|
|
590
|
+
store, // Use persistent storage
|
|
591
|
+
});
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### Conversation Templates
|
|
595
|
+
|
|
596
|
+
```typescript
|
|
597
|
+
import { DeferredSellerTemplates, DeferredBuyerTemplates } from 'moltspay';
|
|
598
|
+
|
|
599
|
+
// Seller offers deferred payment
|
|
600
|
+
DeferredSellerTemplates.offerDeferredPayment({
|
|
601
|
+
service: 'Video Generation',
|
|
602
|
+
price: 3.99,
|
|
603
|
+
netDays: 30,
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
// Seller shows account statement
|
|
607
|
+
const summary = await manager.getAccountSummary(accountId);
|
|
608
|
+
DeferredSellerTemplates.accountStatement(summary);
|
|
609
|
+
|
|
610
|
+
// Buyer requests statement
|
|
611
|
+
DeferredBuyerTemplates.requestStatement();
|
|
612
|
+
|
|
613
|
+
// Buyer announces settlement
|
|
614
|
+
DeferredBuyerTemplates.announceSettlement({
|
|
615
|
+
amount: 3.99,
|
|
616
|
+
txHash: '0xABC...',
|
|
617
|
+
});
|
|
618
|
+
```
|
|
619
|
+
|
|
464
620
|
## Environment Variables
|
|
465
621
|
|
|
466
622
|
```bash
|