moltspay 0.2.4 → 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 +67 -1
- package/dist/cli.js +573 -93
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +577 -95
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +111 -1
- package/dist/index.d.ts +111 -1
- package/dist/index.js +383 -63
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +393 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,7 +80,73 @@ Complete support for pure-conversation payment between AI Agents.
|
|
|
80
80
|
START → 能力识别 → 能力协商 → Onboarding → 服务请求 → 报价 → 支付 → 验证 → 交付 → 收据 → END
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
###
|
|
83
|
+
### Client Agent: Auto-Setup (Recommended - v0.2.5+)
|
|
84
|
+
|
|
85
|
+
The simplest way for a client agent to get started:
|
|
86
|
+
|
|
87
|
+
**First-time setup is automatic:**
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Install (agent does this automatically when calling a paid service)
|
|
90
|
+
npm install moltspay
|
|
91
|
+
|
|
92
|
+
# 2. Initialize wallet (automatic, no gas needed)
|
|
93
|
+
npx moltspay init --chain base
|
|
94
|
+
|
|
95
|
+
# Output:
|
|
96
|
+
# ✅ Agent wallet initialized
|
|
97
|
+
# Address: 0xABC123...
|
|
98
|
+
# Storage: ~/.moltspay
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Request Owner authorization (one-time):**
|
|
102
|
+
```bash
|
|
103
|
+
npx moltspay auth-request --owner 0xOWNER_METAMASK --amount 50 --chain base
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Owner signs (CLI or MetaMask):**
|
|
107
|
+
```bash
|
|
108
|
+
# Owner runs this with their private key
|
|
109
|
+
npx moltspay sign-permit \
|
|
110
|
+
--owner 0xOWNER_METAMASK \
|
|
111
|
+
--spender 0xAGENT_ADDRESS \
|
|
112
|
+
--amount 50 \
|
|
113
|
+
--deadline $(date -d '+7 days' +%s) \
|
|
114
|
+
--nonce 0 \
|
|
115
|
+
--chain base
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Agent spends within allowance:**
|
|
119
|
+
```bash
|
|
120
|
+
npx moltspay spend --to 0xSERVICE_PROVIDER --amount 0.99 --chain base
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Code Example (Auto-Initialize)
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { AgentWallet } from 'moltspay';
|
|
127
|
+
|
|
128
|
+
// Auto-creates wallet on first use (no gas needed)
|
|
129
|
+
const wallet = new AgentWallet({ chain: 'base' });
|
|
130
|
+
console.log('Agent address:', wallet.address);
|
|
131
|
+
|
|
132
|
+
// Generate auth request for Owner
|
|
133
|
+
const request = await wallet.generateAuthRequest({
|
|
134
|
+
ownerAddress: '0xOWNER...',
|
|
135
|
+
amount: 50, // $50 USDC allowance
|
|
136
|
+
});
|
|
137
|
+
console.log(request.message); // Send to Owner
|
|
138
|
+
|
|
139
|
+
// After Owner signs, store permit
|
|
140
|
+
wallet.storePermit(ownerPermit);
|
|
141
|
+
|
|
142
|
+
// Pay for services (USDC comes from Owner's wallet)
|
|
143
|
+
const result = await wallet.spend('0xServiceProvider...', 0.99);
|
|
144
|
+
console.log('Paid:', result.txHash);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Buyer Agent: Create Wallet & Pay (Manual)
|
|
148
|
+
|
|
149
|
+
For more control, you can manually manage wallet creation:
|
|
84
150
|
|
|
85
151
|
```typescript
|
|
86
152
|
import { createWallet, loadWallet, PermitWallet } from 'moltspay';
|