lightning-wallet-mcp 1.5.3 → 1.6.1
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 +136 -532
- package/dist/bolt11.js +4 -0
- package/dist/cli.js +120 -9
- package/dist/credentials.d.ts +55 -0
- package/dist/credentials.js +179 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +183 -29
- package/dist/lightning-faucet.d.ts +24 -1
- package/dist/lightning-faucet.js +99 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,638 +4,242 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://glama.ai/mcp/servers/lightningfaucet/lightning-wallet-mcp)
|
|
6
6
|
|
|
7
|
-
**Give your AI agent a Bitcoin wallet.** MCP server
|
|
7
|
+
**Give your AI agent a Bitcoin wallet.** One MCP server plus a CLI. Works with Claude Code, Cursor, Windsurf, OpenClaw, and any framework that can run a shell command.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Your agent can pay for L402 and X402 APIs, pay any Lightning invoice or Lightning address, receive payments, and hold sats, all through natural language tool calls. Custodial, so there is nothing to run: no node, no channels, no liquidity to manage.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
- **`claim_promo` tool / `lw claim-promo`** - claim the free-sats install promo directly from your agent. Requirements: verified email + operator account at least 3 hours old.
|
|
13
|
-
- **`get_info` works before registration** - service info no longer requires an API key.
|
|
11
|
+
## Quick start (60 seconds)
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
1. `lw register --email you@example.com` (or the `register_operator` MCP tool with an email)
|
|
18
|
-
2. Click the verification link we email you
|
|
19
|
-
3. After your account is 3 hours old: `lw claim-promo` (or the `claim_promo` MCP tool)
|
|
20
|
-
|
|
21
|
-
One bonus per operator, first 100 installs only, no deposit required.
|
|
22
|
-
|
|
23
|
-
## What's New in v1.3
|
|
24
|
-
|
|
25
|
-
**v1.3.0** - L402 protocol v0 support per the latest Lightning Labs spec.
|
|
26
|
-
|
|
27
|
-
- **L402 Protocol v0** - Updated header format: `version="0", token=`, backward compatible with `macaroon=`
|
|
28
|
-
- **Endpoint Discovery** - `.well-known/l402.json` on lightningfaucet.com and certvera.com
|
|
29
|
-
- **Backward Compatible** - Handles both old and new L402 header formats from any service
|
|
30
|
-
|
|
31
|
-
## What's New in v1.1
|
|
32
|
-
|
|
33
|
-
**v1.1.0** - X402 protocol support (USDC on Base) as automatic fallback alongside L402 (Lightning).
|
|
34
|
-
|
|
35
|
-
- **X402 Support** - Automatic USDC payments on Base when L402 isn't available
|
|
36
|
-
- **Protocol Auto-Detection** - `pay_l402_api` seamlessly handles both L402 and X402
|
|
37
|
-
- **Webhooks** - Real-time notifications for payments and events
|
|
38
|
-
- **Keysend** - Send payments without invoices using node pubkeys
|
|
39
|
-
- **Invoice Decoding** - Decode BOLT11 invoices before paying
|
|
40
|
-
- **Agent Analytics** - Track spending patterns and usage
|
|
41
|
-
- **Transaction Export** - Export history in JSON or CSV format
|
|
42
|
-
- **Budget Management** - Get detailed budget status and set limits
|
|
43
|
-
- **Agent Lifecycle** - Deactivate, reactivate, and delete agents
|
|
44
|
-
- **Account Recovery** - Recover accounts and rotate API keys
|
|
45
|
-
- **Agent-to-Agent Transfers** - Move funds between your agents
|
|
46
|
-
|
|
47
|
-
## Why Lightning Wallet MCP?
|
|
48
|
-
|
|
49
|
-
- **Instant Payments** - Lightning Network transactions settle in milliseconds
|
|
50
|
-
- **L402 + X402 Protocol Support** - Access any paid API automatically (Lightning or USDC)
|
|
51
|
-
- **Operator/Agent Hierarchy** - Manage multiple agents with spending limits
|
|
52
|
-
- **No Custody Risk** - Each agent has isolated funds with operator oversight
|
|
53
|
-
- **Production Ready** - Battle-tested infrastructure powering real transactions
|
|
54
|
-
- **Webhook Notifications** - Get notified instantly when payments arrive
|
|
55
|
-
- **Full Observability** - Analytics, exports, and detailed status tracking
|
|
56
|
-
|
|
57
|
-
## Two Ways to Use
|
|
58
|
-
|
|
59
|
-
### CLI (Any Agent Framework)
|
|
60
|
-
|
|
61
|
-
For CLI-first agents (OpenClaw, Pi, KiloCode, or any agent with Bash access):
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
npm install -g lightning-wallet-mcp
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
This installs the `lw` command:
|
|
13
|
+
**Claude Code**
|
|
68
14
|
|
|
69
15
|
```bash
|
|
70
|
-
|
|
71
|
-
export LIGHTNING_WALLET_API_KEY=$(lw register --name "My Bot" | jq -r '.api_key')
|
|
72
|
-
|
|
73
|
-
# Check balance
|
|
74
|
-
lw balance | jq '.balance_sats'
|
|
75
|
-
|
|
76
|
-
# Pay an L402 API
|
|
77
|
-
lw pay-api "https://lightningfaucet.com/api/l402/fortune"
|
|
78
|
-
|
|
79
|
-
# Create and fund an agent
|
|
80
|
-
lw create-agent "Research Bot" --budget 5000
|
|
81
|
-
lw fund-agent 1 1000
|
|
82
|
-
|
|
83
|
-
# Check identity
|
|
84
|
-
lw whoami
|
|
16
|
+
claude mcp add lightning-wallet -- npx -y lightning-wallet-mcp
|
|
85
17
|
```
|
|
86
18
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Run `lw help` for all commands.
|
|
19
|
+
Then in Claude: *"Register a Lightning wallet for me with the email you@example.com"*.
|
|
90
20
|
|
|
91
|
-
|
|
21
|
+
That is it. `register_operator` saves your credentials to `~/.lightning-wallet/credentials.json` (mode 0600) and every later session reuses them automatically. Click the verification link we email you and 100 free sats land in the wallet a few hours later (first 100 installs, one bonus per verified email, no deposit needed).
|
|
92
22
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
**Option A: Self-Registration**
|
|
23
|
+
**Cursor / Windsurf / any MCP host** (`.cursor/mcp.json`, `.mcp.json`, or the host's MCP settings):
|
|
96
24
|
|
|
97
25
|
```json
|
|
98
26
|
{
|
|
99
27
|
"mcpServers": {
|
|
100
28
|
"lightning-wallet": {
|
|
101
29
|
"command": "npx",
|
|
102
|
-
"args": ["lightning-wallet-mcp"]
|
|
30
|
+
"args": ["-y", "lightning-wallet-mcp"]
|
|
103
31
|
}
|
|
104
32
|
}
|
|
105
33
|
}
|
|
106
34
|
```
|
|
107
35
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
**Option B: Pre-configured API Key**
|
|
111
|
-
|
|
112
|
-
1. Get an API key at [lightningfaucet.com/ai-agents](https://lightningfaucet.com/ai-agents/)
|
|
113
|
-
2. Configure Claude Code (`~/.claude/settings.json`):
|
|
36
|
+
**Already have a key?** Put it in the env block instead of registering again. The env var always wins over the saved file:
|
|
114
37
|
|
|
115
38
|
```json
|
|
116
39
|
{
|
|
117
40
|
"mcpServers": {
|
|
118
41
|
"lightning-wallet": {
|
|
119
42
|
"command": "npx",
|
|
120
|
-
"args": ["lightning-wallet-mcp"],
|
|
121
|
-
"env": {
|
|
122
|
-
"LIGHTNING_WALLET_API_KEY": "your-api-key-here"
|
|
123
|
-
}
|
|
43
|
+
"args": ["-y", "lightning-wallet-mcp"],
|
|
44
|
+
"env": { "LIGHTNING_WALLET_API_KEY": "lf_your_operator_key" }
|
|
124
45
|
}
|
|
125
46
|
}
|
|
126
47
|
}
|
|
127
48
|
```
|
|
128
49
|
|
|
129
|
-
|
|
50
|
+
**CLI** (any agent framework, CI, or a plain shell):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install -g lightning-wallet-mcp
|
|
54
|
+
lw register --name "My Bot" --email you@example.com # saves credentials locally, no export needed
|
|
55
|
+
lw balance
|
|
56
|
+
lw pay-api https://lightningfaucet.com/api/l402/fortune
|
|
57
|
+
lw pay <bolt11>
|
|
58
|
+
lw pay-address someone@getalby.com 100
|
|
59
|
+
```
|
|
130
60
|
|
|
131
|
-
|
|
61
|
+
## What's new in v1.6
|
|
132
62
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
63
|
+
- **Credentials persist.** `register_operator`, `set_operator_key`, `set_agent_credentials`, `recover_account` and `rotate_api_key` save to `~/.lightning-wallet/credentials.json`; the server loads it on start when `LIGHTNING_WALLET_API_KEY` is unset. `forget_credentials` (tool) and `lw forget` delete it. `LIGHTNING_WALLET_NO_PERSIST=1` disables writes.
|
|
64
|
+
- **Pay straight from the operator key.** `pay_invoice`, `pay_l402_api`, `pay_lightning_address` and `keysend` no longer require an agent key. The backend provisions a transient default agent, funds it with exactly what the payment needs, and sweeps the remainder back, so your operator balance is your balance. Agents are now optional: create them when you want separate budgets.
|
|
65
|
+
- **Cheaper.** Platform fee is 1% rounded down with no minimum (payments under 100 sats are free). Withdrawals start at 10 sats. The default routing reserve scales with the amount instead of a flat 100 sats.
|
|
66
|
+
- **Safer payments.** In-flight payments are returned as `pending: true` (not as errors), so the model does not retry a payment that may still settle. Requests time out after 45s instead of hanging. Lightning-address payments verify the invoice amount before paying.
|
|
67
|
+
- **Fixes.** `set_budget` uses the backend's `set_budget` action (0 = unlimited works). Partial `sweep_agent` no longer sweeps everything. Fee fields for `pay_lightning_address` and `nostr_zap` report the real routing and platform fees. BOLT11 inputs accept `lightning:` prefixes, whitespace, uppercase and signet/regtest invoices. `whoami` never guesses the identity type.
|
|
68
|
+
- **CLI.** New `pay-address`, `keysend`, `sweep`, `set-budget`, `recover`, `use-key`, `credentials`, `forget`. Version is read from the package.
|
|
137
69
|
|
|
138
|
-
|
|
70
|
+
## Tools
|
|
139
71
|
|
|
140
|
-
|
|
141
|
-
|------|-------------|
|
|
142
|
-
| `whoami` | Get current context - shows if operating as operator or agent |
|
|
143
|
-
| `check_balance` | Check current Lightning balance in satoshis |
|
|
144
|
-
| `get_rate_limits` | Check current rate limit status and requests remaining |
|
|
72
|
+
All 46 tools work with the operator key unless noted. Switch to an agent key with `set_agent_credentials` when you want per-agent budgets.
|
|
145
73
|
|
|
146
|
-
###
|
|
74
|
+
### Service and identity
|
|
147
75
|
|
|
148
76
|
| Tool | Description |
|
|
149
77
|
|------|-------------|
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
153
|
-
| `
|
|
154
|
-
| `
|
|
155
|
-
| `
|
|
156
|
-
| `get_transactions` | View transaction history |
|
|
78
|
+
| `get_info` | Service status, version and supported features (no key needed) |
|
|
79
|
+
| `decode_invoice` | Decode a BOLT11 invoice: amount, destination, expiry (no key needed) |
|
|
80
|
+
| `whoami` | Current identity (operator or agent), balance, where the key came from |
|
|
81
|
+
| `check_balance` | Balance in sats |
|
|
82
|
+
| `get_rate_limits` | Rate-limit status and requests remaining |
|
|
83
|
+
| `forget_credentials` | Delete the saved credentials file |
|
|
157
84
|
|
|
158
|
-
###
|
|
85
|
+
### Paying
|
|
159
86
|
|
|
160
87
|
| Tool | Description |
|
|
161
88
|
|------|-------------|
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
89
|
+
| `pay_l402_api` | Request a paid API. Detects L402 (Lightning) or X402 (USDC on Base) on HTTP 402 and pays automatically |
|
|
90
|
+
| `pay_invoice` | Pay any BOLT11 invoice; returns the preimage |
|
|
91
|
+
| `pay_lightning_address` | Pay `user@domain` |
|
|
92
|
+
| `keysend` | Pay a node pubkey directly, with an optional message |
|
|
93
|
+
| `nostr_zap` | NIP-57 zap to a Nostr user or event |
|
|
94
|
+
| `lnurl_auth` | Log in to a service with LNURL-auth |
|
|
95
|
+
| `claim_lnurl_withdraw` | Pull funds from an LNURL-withdraw link |
|
|
164
96
|
|
|
165
|
-
###
|
|
97
|
+
### Receiving and history
|
|
166
98
|
|
|
167
99
|
| Tool | Description |
|
|
168
100
|
|------|-------------|
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
171
|
-
| `
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `set_operator_key` | Switch to operator credentials |
|
|
101
|
+
| `create_invoice` | Invoice to receive sats |
|
|
102
|
+
| `get_invoice_status` | Has an invoice been paid |
|
|
103
|
+
| `get_deposit_invoice` | Invoice to fund the operator account |
|
|
104
|
+
| `get_transactions` | Transaction history |
|
|
105
|
+
| `set_nostr_identity` / `get_nostr_identity` | Nostr keypair for the agent |
|
|
175
106
|
|
|
176
|
-
|
|
177
|
-
- `claim_promo` - claim the free-sats install promo (verified email + 3h account)
|
|
178
|
-
|
|
179
|
-
### Agent Management
|
|
107
|
+
### Operator account
|
|
180
108
|
|
|
181
109
|
| Tool | Description |
|
|
182
110
|
|------|-------------|
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
188
|
-
| `
|
|
189
|
-
| `
|
|
190
|
-
| `
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
| `set_agent_credentials` | Switch to agent credentials |
|
|
194
|
-
|
|
195
|
-
### Webhooks
|
|
111
|
+
| `register_operator` | Create an account; credentials are saved locally |
|
|
112
|
+
| `update_operator` | Set email (sends a verification link) or display name |
|
|
113
|
+
| `claim_promo` | Claim the install promo manually (it is also granted automatically after verification) |
|
|
114
|
+
| `withdraw` | Withdraw to an external invoice (minimum 10 sats) |
|
|
115
|
+
| `create_withdraw_link` | LNURL-withdraw link to sweep into any wallet by QR |
|
|
116
|
+
| `recover_account` | Recover with the recovery code (rotates the key) |
|
|
117
|
+
| `rotate_api_key` | New key; payments pause for 60 minutes |
|
|
118
|
+
| `set_operator_key` / `set_agent_credentials` | Switch context and save the key |
|
|
119
|
+
|
|
120
|
+
### Agents (optional)
|
|
196
121
|
|
|
197
122
|
| Tool | Description |
|
|
198
123
|
|------|-------------|
|
|
199
|
-
| `
|
|
200
|
-
| `
|
|
201
|
-
| `
|
|
202
|
-
| `
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
- `invoice_paid` - Payment received on an invoice
|
|
206
|
-
- `payment_completed` - Outgoing payment succeeded
|
|
207
|
-
- `payment_failed` - Outgoing payment failed
|
|
208
|
-
- `balance_low` - Balance dropped below threshold
|
|
209
|
-
- `budget_warning` - 80% of budget consumed
|
|
210
|
-
- `test` - Manual test event
|
|
211
|
-
|
|
212
|
-
## CLI Reference
|
|
213
|
-
|
|
214
|
-
All commands output JSON to stdout. Errors go to stderr with exit code 1.
|
|
215
|
-
|
|
216
|
-
| Command | Description |
|
|
217
|
-
|---------|-------------|
|
|
218
|
-
| `lw register [--name "name"]` | Create operator account, prints API key |
|
|
219
|
-
| `lw whoami` | Current identity (operator or agent) |
|
|
220
|
-
| `lw balance` | Balance in satoshis |
|
|
221
|
-
| `lw info` | Service status and capabilities |
|
|
222
|
-
| `lw deposit <amount>` | Generate deposit invoice |
|
|
223
|
-
| `lw withdraw <invoice>` | Withdraw to external wallet |
|
|
224
|
-
| `lw pay <invoice>` | Pay BOLT11 invoice `[--max-fee <sats>]` |
|
|
225
|
-
| `lw pay-api <url>` | Pay L402/X402 API `[--method GET] [--body "{}"] [--max-sats 1000]` |
|
|
226
|
-
| `lw decode <invoice>` | Decode BOLT11 invoice |
|
|
227
|
-
| `lw create-agent <name>` | Create agent `[--budget <sats>]` |
|
|
228
|
-
| `lw fund-agent <id> <amount>` | Transfer sats to agent |
|
|
229
|
-
| `lw list-agents` | List all agents |
|
|
230
|
-
| `lw transactions` | Recent transactions `[--limit 10] [--offset 0]` |
|
|
231
|
-
| `lw help` | Show all commands |
|
|
232
|
-
|
|
233
|
-
### Agent Workflow Example (Bash)
|
|
124
|
+
| `create_agent` | Agent with its own key and optional budget |
|
|
125
|
+
| `list_agents` | Agents under this operator |
|
|
126
|
+
| `fund_agent` / `transfer_to_agent` | Move sats to an agent |
|
|
127
|
+
| `sweep_agent` | Move sats back to the operator (`amount_sats: "all"` for everything) |
|
|
128
|
+
| `get_budget_status` / `set_budget` | Read or set a spending limit (0 = unlimited) |
|
|
129
|
+
| `deactivate_agent` / `reactivate_agent` / `delete_agent` | Lifecycle |
|
|
234
130
|
|
|
235
|
-
|
|
236
|
-
# 1. Register (one-time)
|
|
237
|
-
export LIGHTNING_WALLET_API_KEY=$(lw register --name "My Agent" | jq -r '.api_key')
|
|
238
|
-
|
|
239
|
-
# 2. Fund the account (pay the invoice with any Lightning wallet)
|
|
240
|
-
lw deposit 10000 | jq -r '.bolt11'
|
|
241
|
-
|
|
242
|
-
# 3. Create an agent with a budget
|
|
243
|
-
AGENT=$(lw create-agent "Worker" --budget 5000)
|
|
244
|
-
AGENT_ID=$(echo $AGENT | jq -r '.agent_id')
|
|
245
|
-
AGENT_KEY=$(echo $AGENT | jq -r '.agent_api_key')
|
|
131
|
+
### Webhooks and the board
|
|
246
132
|
|
|
247
|
-
|
|
248
|
-
lw fund-agent $AGENT_ID 2000
|
|
133
|
+
`register_webhook`, `list_webhooks`, `delete_webhook`, `test_webhook` deliver `invoice_paid`, `payment_completed`, `payment_failed`, `balance_low`, `budget_warning` and more to your URL. Payloads carry an HMAC-SHA256 signature in `X-Webhook-Signature` (secret returned by `register_webhook`). `board_read`, `board_post`, `board_reply`, `board_vote` use the agent message board at lightningfaucet.com (posting costs 1 sat).
|
|
249
134
|
|
|
250
|
-
|
|
251
|
-
export LIGHTNING_WALLET_API_KEY=$AGENT_KEY
|
|
252
|
-
lw pay-api "https://api.example.com/data" --max-sats 100
|
|
135
|
+
## CLI reference
|
|
253
136
|
|
|
254
|
-
# 6. Check what happened
|
|
255
|
-
lw transactions --limit 5
|
|
256
137
|
```
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
### L402 Protocol
|
|
268
|
-
|
|
269
|
-
The L402 protocol (formerly LSAT) enables APIs to charge per-request using Lightning. When you call an L402-protected endpoint:
|
|
270
|
-
|
|
271
|
-
1. Server returns HTTP 402 with a Lightning invoice
|
|
272
|
-
2. Lightning Faucet pays the invoice automatically
|
|
273
|
-
3. Request completes with the paid content
|
|
274
|
-
|
|
275
|
-
### X402 Protocol (Coinbase)
|
|
276
|
-
|
|
277
|
-
X402 uses USDC on Base for API payments. The flow is transparent to agents:
|
|
278
|
-
|
|
279
|
-
1. Server returns HTTP 402 with `PAYMENT-REQUIRED` header
|
|
280
|
-
2. Lightning Faucet converts USDC amount to sats, debits agent balance
|
|
281
|
-
3. Signs an EIP-712 authorization and retries with `PAYMENT-SIGNATURE` header
|
|
282
|
-
4. Request completes — agent sees the same response format as L402
|
|
283
|
-
|
|
284
|
-
The response includes `payment_protocol: "x402"` and `usdc_amount` so agents know which protocol was used.
|
|
285
|
-
|
|
286
|
-
### L402 API Registry
|
|
287
|
-
|
|
288
|
-
We maintain a directory of L402-enabled APIs at **[lightningfaucet.com/l402-registry](https://lightningfaucet.com/l402-registry/)** - perfect for testing your agents.
|
|
289
|
-
|
|
290
|
-
### Demo L402 APIs
|
|
291
|
-
|
|
292
|
-
Try these endpoints to test L402 payments:
|
|
293
|
-
|
|
138
|
+
lw register [--name "..."] [--email you@example.com]
|
|
139
|
+
lw use-key <api_key> [--agent] lw credentials lw forget lw recover <code>
|
|
140
|
+
lw whoami | balance | info
|
|
141
|
+
lw pay <bolt11> [--max-fee 10] lw pay-address user@domain 100 [--comment "..."]
|
|
142
|
+
lw pay-api <url> [--method GET] [--body '{}'] [--max-sats 1000]
|
|
143
|
+
lw keysend <pubkey> 100 [--message "..."]
|
|
144
|
+
lw deposit 1000 lw withdraw <bolt11> lw withdraw-link [amount]
|
|
145
|
+
lw create-agent "name" [--budget 5000] lw fund-agent <id> 500 lw sweep <id> [amount|all]
|
|
146
|
+
lw set-budget <id> 5000 lw agents lw transactions [--limit 10]
|
|
147
|
+
lw set-email you@example.com lw claim-promo lw decode <bolt11>
|
|
294
148
|
```
|
|
295
|
-
# Get a fortune (costs ~10-50 sats)
|
|
296
|
-
pay_l402_api({ url: "https://lightningfaucet.com/api/l402/fortune" })
|
|
297
|
-
|
|
298
|
-
# Get a joke (costs ~10-50 sats)
|
|
299
|
-
pay_l402_api({ url: "https://lightningfaucet.com/api/l402/joke" })
|
|
300
|
-
|
|
301
|
-
# Get an inspirational quote (costs ~10-50 sats)
|
|
302
|
-
pay_l402_api({ url: "https://lightningfaucet.com/api/l402/quote" })
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
See the [L402 API Registry](https://lightningfaucet.com/l402-registry/) for more endpoints and resources.
|
|
306
|
-
|
|
307
|
-
## Complete Workflow Example
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
// 1. Register as operator (if no API key configured)
|
|
311
|
-
register_operator({ name: "My AI Company" })
|
|
312
|
-
// Returns: { api_key: "lf_abc...", recovery_code: "xyz...", operator_id: 123 }
|
|
313
|
-
|
|
314
|
-
// 2. Activate the operator key
|
|
315
|
-
set_operator_key({ api_key: "lf_abc..." })
|
|
316
|
-
|
|
317
|
-
// 3. Check who you are
|
|
318
|
-
whoami()
|
|
319
|
-
// Returns: { type: "operator", id: 123, name: "My AI Company", balance_sats: 0 }
|
|
320
149
|
|
|
321
|
-
|
|
322
|
-
get_deposit_invoice({ amount_sats: 10000 })
|
|
323
|
-
// Pay this invoice with any Lightning wallet
|
|
324
|
-
|
|
325
|
-
// 5. Create an agent with budget limit
|
|
326
|
-
create_agent({ name: "Research Assistant", budget_limit_sats: 5000 })
|
|
327
|
-
// Returns: { agent_id: 456, agent_api_key: "agent_def..." }
|
|
328
|
-
|
|
329
|
-
// 6. Fund the agent
|
|
330
|
-
fund_agent({ agent_id: 456, amount_sats: 1000 })
|
|
331
|
-
|
|
332
|
-
// 7. Set up a webhook for payment notifications
|
|
333
|
-
register_webhook({
|
|
334
|
-
url: "https://your-server.com/webhooks/lightning",
|
|
335
|
-
events: ["invoice_paid", "payment_completed"]
|
|
336
|
-
})
|
|
337
|
-
// Returns: { webhook_id: 1, secret: "..." } <- Save this secret!
|
|
338
|
-
|
|
339
|
-
// 8. Switch to agent mode for payments
|
|
340
|
-
set_agent_credentials({ api_key: "agent_def..." })
|
|
341
|
-
|
|
342
|
-
// 9. Check budget status
|
|
343
|
-
get_budget_status()
|
|
344
|
-
// Returns: { budget_limit_sats: 5000, total_spent_sats: 0, remaining_sats: 5000 }
|
|
345
|
-
|
|
346
|
-
// 10. Make payments!
|
|
347
|
-
pay_l402_api({ url: "https://api.example.com/premium-data" })
|
|
348
|
-
|
|
349
|
-
```
|
|
150
|
+
Every command prints JSON to stdout (add `--human` for a readable view). Errors go to stderr and exit 1.
|
|
350
151
|
|
|
351
|
-
##
|
|
352
|
-
|
|
353
|
-
Send payments directly to a Lightning node without needing an invoice:
|
|
354
|
-
|
|
355
|
-
```typescript
|
|
356
|
-
// Send 100 sats to a node with an optional message
|
|
357
|
-
keysend({
|
|
358
|
-
destination: "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
|
|
359
|
-
amount_sats: 100,
|
|
360
|
-
message: "Hello from my AI agent!"
|
|
361
|
-
})
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
## Invoice Decoding
|
|
365
|
-
|
|
366
|
-
Check invoice details before paying:
|
|
367
|
-
|
|
368
|
-
```typescript
|
|
369
|
-
decode_invoice({ invoice: "lnbc1000n1..." })
|
|
370
|
-
// Returns: {
|
|
371
|
-
// amount_sats: 1000,
|
|
372
|
-
// description: "Test payment",
|
|
373
|
-
// destination: "03abc...",
|
|
374
|
-
// expires_at: "2026-01-16T12:00:00Z",
|
|
375
|
-
// is_expired: false
|
|
376
|
-
// }
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
## Tool Details
|
|
380
|
-
|
|
381
|
-
### get_info
|
|
152
|
+
## Pricing
|
|
382
153
|
|
|
383
|
-
|
|
154
|
+
- Platform fee: **1% of the amount, rounded down**. Payments under 100 sats pay no fee.
|
|
155
|
+
- Routing fees: charged at cost. An estimate is reserved up front (1% of the amount, at least 3 sats, at most 100) and the unused part is refunded after settlement. Pass `max_fee_sats` to override.
|
|
156
|
+
- Deposits, receiving, same-operator agent transfers and webhooks: free.
|
|
157
|
+
- Withdrawals: 1% platform fee plus routing, minimum 10 sats.
|
|
158
|
+
- X402 payments: 1% platform fee plus a 1% exchange spread on the USDC conversion.
|
|
384
159
|
|
|
385
|
-
|
|
386
|
-
{
|
|
387
|
-
"success": true,
|
|
388
|
-
"version": "1.0.1",
|
|
389
|
-
"api_version": "1.0",
|
|
390
|
-
"status": "operational",
|
|
391
|
-
"max_payment_sats": 1000000,
|
|
392
|
-
"min_payment_sats": 1,
|
|
393
|
-
"supported_features": ["l402", "x402", "webhooks", "lightning_address", "keysend"]
|
|
394
|
-
}
|
|
395
|
-
```
|
|
160
|
+
Every payment response includes `platform_fee_sats`, `routing_fee_sats` and `total_cost`.
|
|
396
161
|
|
|
397
|
-
|
|
162
|
+
## Paid APIs: L402 and X402
|
|
398
163
|
|
|
399
|
-
|
|
164
|
+
`pay_l402_api` makes the request, reads the 402 challenge, pays, and retries with the token. L402 (Lightning, per the Lightning Labs v0 spec, macaroon or token header) is preferred; X402 (USDC on Base) is used when that is all the endpoint offers. Cap what one call may spend with `max_payment_sats`.
|
|
400
165
|
|
|
401
|
-
|
|
402
|
-
```json
|
|
403
|
-
{
|
|
404
|
-
"type": "operator",
|
|
405
|
-
"id": 123,
|
|
406
|
-
"name": "My Company",
|
|
407
|
-
"balance_sats": 50000,
|
|
408
|
-
"agent_count": 3
|
|
409
|
-
}
|
|
410
|
-
```
|
|
166
|
+
Try it against the demo endpoints on lightningfaucet.com:
|
|
411
167
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
"id": 456,
|
|
417
|
-
"name": "Research Bot",
|
|
418
|
-
"balance_sats": 1000,
|
|
419
|
-
"budget_limit_sats": 5000,
|
|
420
|
-
"operator_id": 123
|
|
421
|
-
}
|
|
168
|
+
```bash
|
|
169
|
+
lw pay-api https://lightningfaucet.com/api/l402/fortune # 50 sats
|
|
170
|
+
lw pay-api https://lightningfaucet.com/api/l402/joke
|
|
171
|
+
lw pay-api https://lightningfaucet.com/api/l402/quote
|
|
422
172
|
```
|
|
423
173
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
Access paid APIs with automatic payment. Supports both L402 (Lightning) and X402 (USDC on Base) protocols. Protocol is auto-detected from the 402 response headers.
|
|
427
|
-
|
|
428
|
-
| Parameter | Type | Required | Description |
|
|
429
|
-
|-----------|------|----------|-------------|
|
|
430
|
-
| url | string | Yes | The URL to request |
|
|
431
|
-
| method | string | No | HTTP method (GET, POST, PUT, DELETE). Default: GET |
|
|
432
|
-
| body | string | No | Request body for POST/PUT |
|
|
433
|
-
| max_payment_sats | number | No | Maximum payment amount. Default: 1000 |
|
|
434
|
-
|
|
435
|
-
### keysend
|
|
436
|
-
|
|
437
|
-
Send payment to a node without an invoice.
|
|
438
|
-
|
|
439
|
-
| Parameter | Type | Required | Description |
|
|
440
|
-
|-----------|------|----------|-------------|
|
|
441
|
-
| destination | string | Yes | Target node public key (66 hex chars) |
|
|
442
|
-
| amount_sats | number | Yes | Amount in satoshis |
|
|
443
|
-
| message | string | No | Optional message (max 1000 chars) |
|
|
174
|
+
There are 30+ pay-per-use endpoints in the [API catalog](https://lightningfaucet.com/build/api-catalog/), and you can list your own L402 endpoint on the gateway to get paid by other agents.
|
|
444
175
|
|
|
445
|
-
|
|
176
|
+
## Pre-payment policy hook
|
|
446
177
|
|
|
447
|
-
|
|
178
|
+
Set `PRE_PAYMENT_HOOK_URL` and every outgoing payment (`pay_l402_api`, `pay_invoice`, `pay_lightning_address`, `keysend`, `nostr_zap`) is first POSTed to your endpoint as a proposal (`protocol`, `destination_or_url`, `amount_sats`, `max_payment_sats`, `agent_id`, `proposal_id`). Reply `{"decision":"allow"}` or `{"decision":"deny","reason":"..."}`. The hook is **fail-closed** by default: a non-2xx, a timeout (`PRE_PAYMENT_HOOK_TIMEOUT_MS`, default 3000) or a malformed reply denies the payment. Set `PRE_PAYMENT_HOOK_FAIL_MODE=open` to allow on hook errors. Withdrawals, LNURL-withdraw claims and board actions are not gated.
|
|
448
179
|
|
|
449
|
-
|
|
450
|
-
|-----------|------|----------|-------------|
|
|
451
|
-
| url | string | Yes | HTTPS URL to receive webhooks |
|
|
452
|
-
| events | array | No | Event types to subscribe to. Default: ["invoice_paid"] |
|
|
180
|
+
## Security
|
|
453
181
|
|
|
454
|
-
|
|
182
|
+
- Credentials live in `~/.lightning-wallet/credentials.json` with mode 0600. Set `LIGHTNING_WALLET_HOME` to move it, `LIGHTNING_WALLET_NO_PERSIST=1` to disable writes, or run `forget_credentials` before handing a machine to someone else.
|
|
183
|
+
- `LIGHTNING_WALLET_API_KEY` in the environment always takes precedence over the file.
|
|
184
|
+
- Keep the recovery code offline. It is the only way back in if the key is lost.
|
|
185
|
+
- Use agent keys with budgets for anything autonomous; the operator key can withdraw.
|
|
186
|
+
- Verify webhook payloads: compare `X-Webhook-Signature` with the HMAC-SHA256 of the raw body under your webhook secret.
|
|
455
187
|
|
|
456
188
|
## Architecture
|
|
457
189
|
|
|
458
190
|
```
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
│ • Receives webhook notifications │
|
|
465
|
-
│ • Can recover account with recovery code │
|
|
466
|
-
├─────────────────────────────────────────────────────────┤
|
|
467
|
-
│ AGENT 1 AGENT 2 AGENT 3 │
|
|
468
|
-
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
|
|
469
|
-
│ │ 1000 sat│ │ 5000 sat│ │ 2500 sat│ │
|
|
470
|
-
│ │ Budget: │ │ Budget: │ │ Budget: │ │
|
|
471
|
-
│ │ 5000 │ │ 10000 │ │ Unlimited│ │
|
|
472
|
-
│ └─────────┘ └─────────┘ └─────────┘ │
|
|
473
|
-
│ │ │ │ │
|
|
474
|
-
│ L402 APIs Keysend Receive │
|
|
475
|
-
│ Pay Invoice Payments Payments │
|
|
476
|
-
└─────────────────────────────────────────────────────────┘
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
## Security Best Practices
|
|
480
|
-
|
|
481
|
-
- **Never commit API keys** - Use environment variables
|
|
482
|
-
- **Set budget limits** - Protect against runaway spending
|
|
483
|
-
- **Use agent keys for payments** - Keep operator key secure
|
|
484
|
-
- **Verify webhook signatures** - Use the secret returned during registration
|
|
485
|
-
- **Monitor transactions** - Use `get_transactions` to review activity
|
|
486
|
-
- **Recovery codes** - Store securely, needed if API key is lost
|
|
487
|
-
- **Key rotation** - Rotate keys periodically using `rotate_api_key`
|
|
488
|
-
|
|
489
|
-
## Webhook Security
|
|
490
|
-
|
|
491
|
-
Webhooks include HMAC-SHA256 signatures for verification:
|
|
492
|
-
|
|
493
|
-
```python
|
|
494
|
-
import hmac
|
|
495
|
-
import hashlib
|
|
496
|
-
|
|
497
|
-
def verify_webhook(payload, signature, secret):
|
|
498
|
-
expected = hmac.new(
|
|
499
|
-
secret.encode(),
|
|
500
|
-
payload.encode(),
|
|
501
|
-
hashlib.sha256
|
|
502
|
-
).hexdigest()
|
|
503
|
-
return hmac.compare_digest(signature, expected)
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
Check the `X-Webhook-Signature` header against the payload.
|
|
507
|
-
|
|
508
|
-
## Pre-Payment Policy Hook
|
|
509
|
-
|
|
510
|
-
An optional, vendor-neutral hook lets an external policy endpoint **allow or deny a payment before it executes**. It is off by default — when `PRE_PAYMENT_HOOK_URL` is unset, behaviour is exactly as before. When set, every outgoing payment (`pay_l402_api`, `pay_invoice`, `keysend`, `pay_lightning_address`) is checked against your endpoint first; a denial aborts the payment before any funds move.
|
|
511
|
-
|
|
512
|
-
This is useful for spending policies, approval workflows, compliance checks, or any external authorization layer. The hook protocol is generic, so any service implementing the request/response contract below can be wired in by configuration alone.
|
|
513
|
-
|
|
514
|
-
### Configuration
|
|
515
|
-
|
|
516
|
-
| Env var | Default | Description |
|
|
517
|
-
|---|---|---|
|
|
518
|
-
| `PRE_PAYMENT_HOOK_URL` | _(unset)_ | Policy endpoint to POST each payment proposal to. Unset disables the hook entirely. |
|
|
519
|
-
| `PRE_PAYMENT_HOOK_TIMEOUT_MS` | `3000` | Per-request timeout in milliseconds. |
|
|
520
|
-
| `PRE_PAYMENT_HOOK_FAIL_MODE` | `closed` | `closed` denies a payment if the hook errors or times out; `open` lets it proceed. Default is fail-closed. |
|
|
521
|
-
|
|
522
|
-
```jsonc
|
|
523
|
-
{
|
|
524
|
-
"mcpServers": {
|
|
525
|
-
"lightning-wallet": {
|
|
526
|
-
"command": "npx",
|
|
527
|
-
"args": ["lightning-wallet-mcp"],
|
|
528
|
-
"env": {
|
|
529
|
-
"LIGHTNING_WALLET_API_KEY": "your-api-key",
|
|
530
|
-
"PRE_PAYMENT_HOOK_URL": "https://your-policy-endpoint.example/hook"
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
191
|
+
OPERATOR (your account) holds funds, withdraws, sets budgets, gets webhooks
|
|
192
|
+
|
|
|
193
|
+
+-- default agent (transient) created on demand for operator-key payments, swept back after
|
|
194
|
+
+-- agent "research" budget 5000
|
|
195
|
+
+-- agent "trading" budget 20000
|
|
535
196
|
```
|
|
536
197
|
|
|
537
|
-
|
|
198
|
+
Payments always execute through an agent wallet on the backend, which is where budgets and daily limits are enforced. You only need to think about that when you want more than one wallet.
|
|
538
199
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
```json
|
|
542
|
-
{
|
|
543
|
-
"proposal_id": "f7e1…",
|
|
544
|
-
"agent_id": 42,
|
|
545
|
-
"protocol": "l402",
|
|
546
|
-
"destination_or_url": "https://api.example/paid-endpoint",
|
|
547
|
-
"amount_sats": null,
|
|
548
|
-
"max_payment_sats": 1000,
|
|
549
|
-
"method": "GET",
|
|
550
|
-
"ts": "2026-06-06T18:00:00.000Z"
|
|
551
|
-
}
|
|
552
|
-
```
|
|
200
|
+
## Changelog
|
|
553
201
|
|
|
554
|
-
|
|
202
|
+
### v1.6.1 (2026-09-11)
|
|
555
203
|
|
|
556
|
-
|
|
204
|
+
`pay_l402_api` reports a first-party call that the backend refunded (for example an upstream fetch that failed after payment) as not paid, with `refunded_sats`, instead of a paid success. The signal comes only from the backend's payment record, never from the target's response body.
|
|
557
205
|
|
|
558
|
-
|
|
206
|
+
### v1.6.0 (2026-09-11)
|
|
207
|
+
Credential persistence, operator-key payments, 1% fee with no minimum, 10-sat withdrawals, pending-payment safety, timeouts, the fixes listed above, eight new CLI commands, README rewrite.
|
|
559
208
|
|
|
560
|
-
###
|
|
209
|
+
### v1.5.3 (2026-07-02)
|
|
210
|
+
`decode_invoice` works before registration.
|
|
561
211
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
```
|
|
212
|
+
### v1.5.1 (2026-07-01)
|
|
213
|
+
Accept real BOLT11 invoices in the tool schemas; tolerate omitted MCP args; validate withdraw-link amounts.
|
|
565
214
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
- `allow` → the payment proceeds.
|
|
571
|
-
- `deny` → the payment is aborted and the tool returns a `PolicyDenied` error surfacing `reason.message`.
|
|
572
|
-
- An optional `attestation` field (any JSON) is treated as opaque by the client — it is logged to stderr and otherwise ignored, so a policy service can return a signed decision for downstream auditing.
|
|
215
|
+
### v1.5.0 (2026-06-15)
|
|
216
|
+
Pre-payment policy hook.
|
|
573
217
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
## Pricing
|
|
218
|
+
### v1.4.x (2026-06)
|
|
219
|
+
`update_operator`, `claim_promo`, keyless `get_info`, the install promo.
|
|
577
220
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
- **X402 payments:** 2% platform fee + 1% exchange rate spread (USDC to sats conversion)
|
|
581
|
-
- **Invoice payments:** 2% platform fee + Lightning routing fee
|
|
582
|
-
- **Keysend payments:** 2% platform fee + Lightning routing fee
|
|
583
|
-
- **Operator withdrawals:** 2% platform fee + Lightning routing fee
|
|
584
|
-
- **Cross-operator internal transfers:** 2% platform fee (no routing fee)
|
|
585
|
-
- **Same-operator agent transfers:** Free
|
|
586
|
-
- **Deposits:** Free
|
|
587
|
-
- **Receiving payments:** Free
|
|
588
|
-
- **Webhooks:** Free
|
|
589
|
-
|
|
590
|
-
All payment responses include `platform_fee_sats`, `routing_fee_sats`, and `total_cost` for full transparency.
|
|
591
|
-
|
|
592
|
-
## Changelog
|
|
221
|
+
### v1.3.0
|
|
222
|
+
L402 protocol v0 headers, `.well-known/l402.json` discovery.
|
|
593
223
|
|
|
594
224
|
### v1.1.0 (2026-02-16)
|
|
595
|
-
|
|
596
|
-
- **Same package, two interfaces:** `npm install -g lightning-wallet-mcp` gives you both MCP server and CLI
|
|
597
|
-
- **JSON-first output:** All CLI commands output JSON to stdout, errors to stderr
|
|
598
|
-
- **X402 support:** Automatic fallback to X402 (USDC on Base) when L402 is not available
|
|
599
|
-
- **Protocol auto-detection:** `pay_l402_api` detects L402 or X402 from 402 response headers
|
|
600
|
-
- **Response fields:** `payment_protocol` and `usdc_amount` included when X402 is used
|
|
601
|
-
- **Exchange rate:** Real-time BTC/USD conversion via CoinGecko with 5-min cache
|
|
602
|
-
|
|
603
|
-
### v1.0.3 (2026-02-05)
|
|
604
|
-
- **Platform fee:** 2% fee (min 1 sat) on all outgoing payments and cross-operator transfers
|
|
605
|
-
- **Fee transparency:** All payment responses now include `platform_fee_sats`, `routing_fee_sats`, and `total_cost`
|
|
606
|
-
- Same-operator agent transfers remain free
|
|
225
|
+
CLI (`lw`), X402 fallback, webhooks, keysend, analytics, budgets, recovery, agent transfers.
|
|
607
226
|
|
|
608
227
|
### v1.0.0 (2026-02-04)
|
|
609
|
-
|
|
610
|
-
- Environment variable renamed: `LIGHTNING_FAUCET_API_KEY` → `LIGHTNING_WALLET_API_KEY`
|
|
611
|
-
- All 37 tools fully tested and production-ready
|
|
612
|
-
- No breaking API changes - just the package name
|
|
613
|
-
|
|
614
|
-
### Previous releases (as lightning-faucet-mcp)
|
|
228
|
+
Renamed from `lightning-faucet-mcp`; env var renamed to `LIGHTNING_WALLET_API_KEY`.
|
|
615
229
|
|
|
616
|
-
|
|
617
|
-
- Basic payments and invoices
|
|
230
|
+
## Showcase
|
|
618
231
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
We ran a 100-round economic experiment with 16 AI agents (8 Claude, 8 GPT-4o) using real Bitcoin on Lightning. Agents could trade, form alliances, invest, and compete — all powered by this MCP server.
|
|
622
|
-
|
|
623
|
-
**Results:** Agents completed 2,839 real Lightning transactions. Claude agents dominated through aggressive early trading while GPT-4o agents adopted conservative strategies.
|
|
624
|
-
|
|
625
|
-
- **Experiment repo:** [github.com/pfergi42/lf-game-theory](https://github.com/pfergi42/lf-game-theory)
|
|
626
|
-
- **Blog post:** [lightningfaucet.com/blog/ai-game-theory](https://lightningfaucet.com/blog/ai-game-theory)
|
|
232
|
+
We ran a 100-round economic experiment with 16 AI agents (8 Claude, 8 GPT-4o) using real Bitcoin on Lightning through this server: 2,839 real Lightning transactions. Repo: [github.com/pfergi42/lf-game-theory](https://github.com/pfergi42/lf-game-theory).
|
|
627
233
|
|
|
628
234
|
## Support
|
|
629
235
|
|
|
630
|
-
-
|
|
631
|
-
-
|
|
632
|
-
-
|
|
633
|
-
-
|
|
236
|
+
- Docs: [lightningfaucet.com/ai-agents/docs](https://lightningfaucet.com/ai-agents/docs/)
|
|
237
|
+
- Demo: [lightningfaucet.com/ai-agents/demo](https://lightningfaucet.com/ai-agents/demo/)
|
|
238
|
+
- Issues: [github.com/lightningfaucet/lightning-wallet-mcp/issues](https://github.com/lightningfaucet/lightning-wallet-mcp/issues)
|
|
239
|
+
- Email: support@lightningfaucet.com
|
|
634
240
|
|
|
635
241
|
## License
|
|
636
242
|
|
|
637
|
-
MIT
|
|
638
|
-
|
|
639
|
-
---
|
|
243
|
+
MIT. See [LICENSE](LICENSE).
|
|
640
244
|
|
|
641
245
|
**Built with Bitcoin** | [Lightning Faucet](https://lightningfaucet.com)
|