@springmint/x402-payment 1.0.0 → 1.0.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
@@ -148,9 +148,27 @@ npx @springmint/x402-payment \
148
148
  | `--input` | No | JSON request body |
149
149
  | `--method` | No | HTTP method (default: GET for direct, POST for entrypoint) |
150
150
  | `--check` | No | Verify wallet configuration and exit |
151
+ | `--approve` | No | Approve token spending (requires `--token` and `--network`) |
152
+ | `--allowance` | No | Check current token allowance (requires `--token` and `--network`) |
153
+ | `--token` | No | Token contract address (used with `--approve` / `--allowance`) |
154
+ | `--network` | No | Network identifier, e.g. `eip155:97`, `tron:nile` (used with `--approve` / `--allowance`) |
155
+ | `--type` | No | Chain type: `evm` (default) or `tron` (used with `--approve` / `--allowance`) |
151
156
 
152
157
  Output goes to **stdout** as JSON. Logs go to **stderr**.
153
158
 
159
+ **Token approval examples:**
160
+
161
+ ```bash
162
+ # Check USDT allowance on BSC testnet
163
+ npx @springmint/x402-payment --allowance --token 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd --network eip155:97
164
+
165
+ # Approve USDT on BSC testnet
166
+ npx @springmint/x402-payment --approve --token 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd --network eip155:97
167
+
168
+ # Approve USDT on TRON nile
169
+ npx @springmint/x402-payment --approve --token TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf --network tron:nile --type tron
170
+ ```
171
+
154
172
  ## API Reference
155
173
 
156
174
  ### `createX402FetchClient(options?)`
@@ -190,6 +208,23 @@ Search for a private key following the lookup order described in [Wallet Configu
190
208
 
191
209
  Search for TronGrid API key using the same lookup order.
192
210
 
211
+ ### `checkAllowance(type, token, network, options?)`
212
+
213
+ Check current token allowance for the wallet.
214
+
215
+ ```ts
216
+ const allowance = await checkAllowance("evm", "0x55d3...7955", "eip155:56");
217
+ console.log(`Allowance: ${allowance}`);
218
+ ```
219
+
220
+ ### `approveToken(type, token, network, options?)`
221
+
222
+ Approve unlimited token spending for x402 payments.
223
+
224
+ ```ts
225
+ await approveToken("evm", "0x55d3...7955", "eip155:56");
226
+ ```
227
+
193
228
  ## Supported Networks & Tokens
194
229
 
195
230
  | Chain | Network | Tokens | Example USDT Contract |
@@ -201,32 +236,104 @@ Search for TronGrid API key using the same lookup order.
201
236
 
202
237
  Both **direct transfer** and **permit-based** payment mechanisms are supported on all chains.
203
238
 
204
- ## For AI Agent Skill Developers
239
+ ## Create Your Own Skill with x402 Payment
205
240
 
206
- If you're building a skill that calls a paid API, add this package as a dependency:
241
+ If you have a paid API protected by x402, you can create a skill file so AI agents can call it automatically.
207
242
 
208
- ```bash
209
- npm install @springmint/x402-payment
210
- ```
243
+ ### Step 1: Create SKILL.md
211
244
 
212
- Then in your skill's code:
245
+ Create a `SKILL.md` file for your API:
213
246
 
214
- ```ts
247
+ ```markdown
248
+ ---
249
+ name: my-api-skill
250
+ description: "Description of your API and when to use it."
251
+ version: 1.0.0
252
+ dependencies:
253
+ - "@springmint/x402-payment"
254
+ ---
255
+
256
+ # My API Skill
257
+
258
+ > **Prerequisites**: Install and configure `@springmint/x402-payment`.
259
+ > See [wallet configuration](https://github.com/springmint/x402-payment#wallet-configuration).
260
+ >
261
+ > ```bash
262
+ > npm install @springmint/x402-payment
263
+ > npx @springmint/x402-payment --check
264
+ > ```
265
+
266
+ ## Endpoint
267
+
268
+ \`\`\`
269
+ POST https://your-api.com/api/your-endpoint
270
+ Content-Type: application/json
271
+ \`\`\`
272
+
273
+ ## Using with x402-payment
274
+
275
+ ### CLI (AI Agent)
276
+
277
+ \`\`\`bash
278
+ npx @springmint/x402-payment \
279
+ --url https://your-api.com/api/your-endpoint \
280
+ --method POST \
281
+ --input '{"key": "value"}'
282
+ \`\`\`
283
+
284
+ ### Library (Node.js)
285
+
286
+ \`\`\`ts
215
287
  import { createX402FetchClient } from "@springmint/x402-payment";
216
288
 
217
289
  const client = await createX402FetchClient();
218
- const res = await client.request("https://your-paid-api.com/endpoint", {
290
+ const response = await client.request("https://your-api.com/api/your-endpoint", {
219
291
  method: "POST",
220
292
  headers: { "Content-Type": "application/json" },
221
- body: JSON.stringify({ /* your request */ }),
293
+ body: JSON.stringify({ key: "value" }),
222
294
  });
295
+ const data = await response.json();
296
+ \`\`\`
297
+
298
+ ## Request / Response
299
+
300
+ [Document your API parameters and response format here]
301
+
302
+ ## Error Handling
303
+
304
+ ### Insufficient Allowance
305
+
306
+ \`\`\`bash
307
+ npx @springmint/x402-payment --approve --token <TOKEN_ADDRESS> --network <NETWORK>
308
+ \`\`\`
223
309
  ```
224
310
 
225
- And in your skill's `SKILL.md`, declare the dependency:
311
+ ### Step 2: Agent Workflow
226
312
 
227
- ```yaml
228
- dependencies:
229
- - x402-payment
313
+ When an AI agent receives your skill, the complete flow is:
314
+
315
+ ```
316
+ 1. Agent reads SKILL.md
317
+
318
+ 2. Checks if @springmint/x402-payment is installed
319
+ └─ If not: runs `npm install @springmint/x402-payment`
320
+
321
+ 3. Verifies wallet: `npx @springmint/x402-payment --check`
322
+ └─ If no wallet: asks user to configure private key
323
+
324
+ 4. Calls your API via CLI or library
325
+
326
+ 5. Gets 402 → SDK auto-pays → gets result
327
+
328
+ 6. If allowance error: runs --approve, then retries
329
+ ```
330
+
331
+ ### Step 3: Publish
332
+
333
+ Put your `SKILL.md` in a git repository. AI agents can use it by reading the file:
334
+
335
+ ```
336
+ Read my-api-skill/SKILL.md and call the API with {"key": "value"}
230
337
  ```
231
338
 
232
339
  See [cpbox-skills/batch-balance](https://github.com/springmint/cpbox-skills) for a real-world example.
package/SKILL.md CHANGED
@@ -7,7 +7,7 @@ compatibility:
7
7
  tools:
8
8
  - x402_invoke
9
9
  metadata:
10
- version: 1.0.0
10
+ version: 1.0.2
11
11
  author: cppay.finance
12
12
  homepage: https://x402.org
13
13
  tags: [crypto, payments, x402, agents, api, usdt, usdd, usdc, tron, ethereum, evm, erc20, trc20, sdk]
@@ -33,11 +33,9 @@ When an HTTP `402 Payment Required` response is received, the package automatica
33
33
 
34
34
  ## Prerequisites
35
35
 
36
- - **Wallet Configuration**:
37
- - **TRON**: Set `TRON_PRIVATE_KEY` for TRC20 payments (USDT/USDD).
38
- - **EVM**: Set `EVM_PRIVATE_KEY` or `ETH_PRIVATE_KEY` for ERC20 payments (USDT/USDC).
39
- - The skill also searches for keys in `x402-config.json` and `~/.mcporter/mcporter.json`.
40
- - **TronGrid API Key**: Required for **Mainnet** to avoid rate limits (`TRON_GRID_API_KEY`).
36
+ 1. Install: `npm install @springmint/x402-payment`
37
+ 2. Configure wallet see [Wallet Configuration](https://github.com/springmint/x402-payment#wallet-configuration) for all supported methods (environment variables, `x402-config.json`, `~/.mcporter/mcporter.json`)
38
+ 3. Verify: `npx @springmint/x402-payment --check`
41
39
 
42
40
  ## Usage as a Library
43
41
 
@@ -148,7 +146,23 @@ If the endpoint returns an image or binary data (CLI mode only):
148
146
 
149
147
  ### Insufficient Allowance
150
148
 
151
- If allowance is insufficient, the tool will automatically attempt an "infinite approval" transaction. Ensure you have native tokens (TRX or BNB/ETH) for gas.
149
+ If you get an allowance error, approve the token first:
150
+
151
+ ```bash
152
+ # Check current allowance
153
+ npx @springmint/x402-payment --allowance --token <TOKEN_ADDRESS> --network <NETWORK>
154
+
155
+ # Approve token spending
156
+ npx @springmint/x402-payment --approve --token <TOKEN_ADDRESS> --network <NETWORK>
157
+ ```
158
+
159
+ Or in code:
160
+ ```ts
161
+ import { approveToken } from "@springmint/x402-payment";
162
+ await approveToken("evm", "0x55d3...7955", "eip155:97");
163
+ ```
164
+
165
+ Ensure you have native tokens (TRX or BNB/ETH) for gas.
152
166
 
153
167
  ### Insufficient Balance
154
168
 
@@ -17,7 +17,7 @@ __webpack_require__.d(__webpack_exports__, {
17
17
  // EXTERNAL MODULE: ./node_modules/viem/_esm/actions/public/call.js + 1 modules
18
18
  var call = __webpack_require__(8454);
19
19
  // EXTERNAL MODULE: ./node_modules/viem/_esm/utils/stringify.js
20
- var stringify = __webpack_require__(2162);
20
+ var stringify = __webpack_require__(9781);
21
21
  // EXTERNAL MODULE: ./node_modules/viem/_esm/errors/base.js + 1 modules
22
22
  var base = __webpack_require__(9298);
23
23
  // EXTERNAL MODULE: ./node_modules/viem/_esm/errors/utils.js