@springmint/x402-payment 1.0.1 → 1.0.3
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 +120 -13
- package/SKILL.md +18 -2
- package/dist/cli/{743.index.js → 618.index.js} +442 -236
- package/dist/cli/client.d.ts +19 -0
- package/dist/cli/client.d.ts.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/x402_invoke.js +96 -3
- package/dist/lib/client.d.ts +19 -0
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +45 -0
- package/dist/lib/client.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/package.json +2 -2
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
|
-
##
|
|
239
|
+
## Create Your Own Skill with x402 Payment
|
|
205
240
|
|
|
206
|
-
If you
|
|
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
|
-
|
|
209
|
-
npm install @springmint/x402-payment
|
|
210
|
-
```
|
|
243
|
+
### Step 1: Create SKILL.md
|
|
211
244
|
|
|
212
|
-
|
|
245
|
+
Create a `SKILL.md` file for your API:
|
|
213
246
|
|
|
214
|
-
```
|
|
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
|
|
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({
|
|
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
|
-
|
|
311
|
+
### Step 2: Agent Workflow
|
|
226
312
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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.
|
|
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]
|
|
@@ -146,7 +146,23 @@ If the endpoint returns an image or binary data (CLI mode only):
|
|
|
146
146
|
|
|
147
147
|
### Insufficient Allowance
|
|
148
148
|
|
|
149
|
-
If
|
|
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.
|
|
150
166
|
|
|
151
167
|
### Insufficient Balance
|
|
152
168
|
|