Bitcoin Lightning wallet for agents — balances, invoices, payments, BTC/USD swaps, QR codes, price conversion, transaction history, and L402 auto-pay client via the Blink API. All output is JSON.
Bitcoin Lightning wallet operations via the Blink API. Enables agents to check balances, receive payments via invoices, send payments over Lightning, track transactions, monitor prices, and automatically pay for L402-gated web services.
Blink is a custodial Bitcoin Lightning wallet with a GraphQL API. Key concepts:
blink_...) with scoped permissions (Read, Receive, Write)lnbc...) used to receive paymentsuser@domain) for sending payments without an invoicebash and Node.js 18+.BLINK_API_KEY environment variable with appropriate scopes.--experimental-websocket.node:util, node:fs, node:path, node:child_process).Use this skill for concrete wallet operations, not generic Lightning theory.
CODEBLOCK0
API Key Scopes:
Tip: Start with Read + Receive only. Add Write when you need to send payments.
CODEBLOCK1
If you see JSON with your wallet balances, you're ready.
To use the Blink staging environment (signet) instead of real money:
CODEBLOCK2
Create a staging API key at dashboard.staging.blink.sv. The staging environment uses signet bitcoin (no real value) — perfect for testing payment flows safely.
If BLINK_API_URL is not set, production (https://api.blink.sv/graphql) is used by default.
Scripts automatically resolve BLINK_API_KEY using this order:
process.env.BLINK_API_KEY (checked first)~/.profile, ~/.bashrc, ~/.bash_profile, ~/.zshrc — scanned for an export BLINK_API_KEY=... line onlyNo source ~/.profile prefix is needed. The rc file scan uses a targeted regex that reads only the BLINK_API_KEY export line — no other data is extracted from these files.
If you have cloned the full GitHub repo, you can optionally install a blink CLI command:
CODEBLOCK3
Note:
npm linkmodifies global npm state. This is optional — all functionality is available by running scripts directly withnode {baseDir}/scripts/<script>.js. The ClawHub-installed version does not require or usenpm link.
These rules are mandatory for any AI agent using this skill:
pay-invoice, pay-lnaddress, pay-lnurl, or swap-execute without explicit user confirmation of the amount and recipient.--dry-run before executing for real unless the user explicitly says to skip it.balance before any payment or swap to verify sufficient funds.fee-probe before pay-invoice to show the user the fee cost.BLINK_API_KEY as a secret. Do not echo it, include it in messages, or write it to files.BLINK_API_URL to the staging endpoint.l402-pay without dry-running first (--dry-run) and confirming the satoshi amount with the user. The token cache (~/.blink/l402-tokens.json) means subsequent calls may reuse a paid token silently — inform the user when a cached token is used.btcBalanceUsdFormatted, usdBalanceFormatted).blink price <sats> or the btcBalanceUsd field from balance output instead.--unit flag controls interpretation: sats for BTC, cents for USD.BLINK_API_KEY with the correct scopes for your operation.BLINK_API_URL for staging/testnet.blink balance.blink fee-probe.--wallet flag.blink swap-quote.blink swap-execute (use --dry-run first).postBalance/balanceDelta.blink l402-discover <url> (no payment needed).blink l402-pay <url> --dry-run and confirm cost with user.blink l402-pay <url> --max-amount <sats> (Write scope required).CODEBLOCK4
CODEBLOCK5
Returns JSON with all wallet balances (BTC in sats, USD in cents), wallet IDs, pending incoming amounts, and a pre-computed USD estimate for the BTC wallet. Use btcBalanceUsd for the BTC wallet's USD value — do not calculate it yourself.
CODEBLOCK6
Generates a BOLT-11 Lightning invoice for the specified amount in satoshis. Returns the paymentRequest string that can be paid by any Lightning wallet. The BTC wallet ID is resolved automatically.
Auto-subscribe: After creating the invoice, the script automatically opens a WebSocket subscription and waits for payment. It outputs two JSON objects to stdout:
{"event": "invoice_created", ...} with paymentRequest, paymentHash, etc.The agent should read the first JSON to share the invoice/QR with the user right away, then wait for the second JSON to confirm payment.
amount_sats — amount in satoshis (required)CODEBLOCK7
Creates a Lightning invoice denominated in USD cents. The sender pays in BTC/Lightning, but the received amount is locked to a USD value at the current exchange rate. Credited to the USD wallet. Expires in ~5 minutes due to exchange rate lock.
Auto-subscribe: Same two-phase output as create-invoice — first JSON is the created invoice, second JSON is the payment resolution (PAID/EXPIRED/TIMEOUT).
amount_cents — amount in USD cents, e.g. 100 = $1.00 (required)CODEBLOCK8
Checks the payment status of a Lightning invoice by its payment hash. Use after creating an invoice to detect when it has been paid. Returns status: PAID, PENDING, or EXPIRED.
payment_hash — the 64-char hex payment hash from create-invoice output (required)CODEBLOCK9
Pays a BOLT-11 Lightning invoice from the BTC or USD wallet. Returns payment status: SUCCESS, PENDING, FAILURE, or ALREADY_PAID. The wallet ID is resolved automatically.
bolt11_invoice — the BOLT-11 payment request string, e.g. lnbc... (required)Requires Write scope on the API key.
AGENT: This command spends funds. Always run
balanceandfee-probefirst, then confirm amount and recipient with the user before executing.
CODEBLOCK10
Sends satoshis to a Lightning Address (e.g. user@blink.sv). Returns payment status. The wallet ID is resolved automatically.
lightning_address — recipient in user@domain format (required)Requires Write scope on the API key.
AGENT: This command spends funds. Always run
balancefirst, confirm the Lightning Address and amount with the user, then execute.
CODEBLOCK11
Sends satoshis to a raw LNURL payRequest string. For Lightning Addresses (user@domain), use pay-lnaddress instead.
lnurl — LNURL string, e.g. lnurl1... (required)Requires Write scope on the API key.
AGENT: This command spends funds. Always run
balancefirst, confirm the LNURL and amount with the user, then execute.
CODEBLOCK12
Estimates the fee for paying a Lightning invoice without actually sending. Use before pay-invoice to check costs. Payments to other Blink users and direct-channel nodes are free (0 sats).
bolt11_invoice — the BOLT-11 payment request string (required)lnUsdInvoiceFeeProbe to estimate fees from the USD wallet's perspective.CODEBLOCK13
Renders a terminal QR code for a Lightning invoice (BOLT-11) to stderr and generates a PNG image file to /tmp. The stdout JSON includes a pngPath field with the absolute path to the PNG file.
Sending the QR image to a user: After running this script, use the pngPath from the JSON output to send the PNG as a media attachment to the user in the current chat. The agent should use its native message-send capability with the file path.
bolt11_invoice — the BOLT-11 payment request string (required)Output JSON includes:
invoice — uppercased invoice string"L" (LOW)/tmp/blink_qr_1234567890.png)CODEBLOCK14
Lists recent transactions (incoming and outgoing) with pagination. Returns direction, amount, status, type (lightning/onchain/intraledger), and metadata.
--first N — number of transactions to return (default: 20, max: 100)CODEBLOCK15
Multi-purpose exchange rate tool. All price queries are public (no API key required), though the key is sent if available.
Modes:
<amount_sats> — convert a satoshi amount to USD (e.g. blink price 1760 → $1.20)--usd <amount> — convert a USD amount to sats (e.g. blink price --usd 5.00 → 7350 sats)--history <range> — historical BTC price data with summary stats (high/low/change). Ranges: ONE_DAY, ONE_WEEK, ONE_MONTH, ONE_YEAR, INLINECODE133--currencies — list all supported display currencies (IDs, names, symbols, flags)CODEBLOCK16
Shows account level, spending limits (withdrawal, internal send, convert), default wallet, and wallet summary with pre-computed USD estimates for BTC balances. Limits are denominated in USD cents with a rolling 24-hour window.
Blink supports GraphQL subscriptions over WebSocket using the graphql-transport-ws protocol. Requires Node 22+ for native WebSocket, or Node 20+ with the --experimental-websocket flag.
CODEBLOCK17
Watches a single invoice and exits when it is PAID or EXPIRED. Status updates are printed to stderr. JSON result is printed to stdout.
CODEBLOCK18
Streams account updates in real time. Each event is output as a JSON line (NDJSON) to stdout. Use --max to stop after N events.
| Operation | GraphQL | Scope Required |
|---|---|---|
| Check balance | INLINECODE138 + INLINECODE139 | Read |
| Create BTC invoice |
mutation lnInvoiceCreate | Receive |
| Create USD invoice | mutation lnUsdInvoiceCreate | Receive |
| Check invoice | query invoiceByPaymentHash | Read |
| Pay invoice | mutation lnInvoicePaymentSend | Write |
| Pay LN address | mutation lnAddressPaymentSend | Write |
| Pay LNURL | mutation lnurlPaymentSend | Write |
| Fee estimate (BTC) | mutation lnInvoiceFeeProbe | Read |
| Fee estimate (USD) | mutation lnUsdInvoiceFeeProbe | Read |
| Swap BTC→USD | mutation intraLedgerPaymentSend | Write |
| Swap USD→BTC | mutation intraLedgerUsdPaymentSend | Write |
| Transactions | query transactions | Read |
| Price / convert | query currencyConversionEstimation | None (public) |
| Price history | query btcPriceList | None (public) |
| Currency list | query currencyList | None (public) |
| Realtime price | query realtimePrice | None (public) |
| Account info | query me + currencyConversionEstimation | Read |
| Subscribe invoice | subscription lnInvoicePaymentStatus | Read |
| Subscribe updates | subscription myUpdates | Read |
| L402 discover | external HTTP (no Blink API) | None |
| L402 pay | mutation lnInvoicePaymentSend (on 402) | Write |
API Endpoint: https://api.blink.sv/graphql (production)
Authentication: X-API-KEY header
USD wallet notes: The lnInvoicePaymentSend, lnAddressPaymentSend, and lnurlPaymentSend mutations all accept either a BTC or USD wallet ID. When a USD wallet ID is provided, the API debits the USD equivalent automatically. Amounts for lnAddressPaymentSend and lnurlPaymentSend are always specified in satoshis regardless of wallet type.
All commands output structured JSON to stdout. Status messages and errors go to stderr. Exit code 0 on success, 1 on failure.
CODEBLOCK19
First JSON (immediate):
CODEBLOCK20
Second JSON (when payment resolves):
CODEBLOCK21
CODEBLOCK22
CODEBLOCK23
CODEBLOCK24
CODEBLOCK25
CODEBLOCK26
CODEBLOCK27
CODEBLOCK28
CODEBLOCK29
Important: The create-invoice command outputs two JSON objects separated by a newline. Parse them as separate JSON objects, not as a single JSON array. The first object arrives immediately; the second arrives when payment status resolves.
CODEBLOCK30
CODEBLOCK31
CODEBLOCK32
CODEBLOCK33
CODEBLOCK34
CODEBLOCK35
CODEBLOCK36
CODEBLOCK37
CODEBLOCK38
CODEBLOCK39
Swap between your BTC and USD wallets using Blink's intra-ledger transfer. This is an internal conversion (not a Lightning payment), so there are no routing fees — only minor rounding spread.
CODEBLOCK40
Estimates the conversion terms without moving funds. Returns wallet balances, exchange rate snapshot, and the expected amountIn/amountOut in the output JSON.
direction — btc-to-usd or usd-to-btc (aliases: sell-btc, buy-usd, sell-usd, buy-btc)sats for btc-to-usd, cents for usd-to-btc)No API key scope beyond Read is required for quotes.
CODEBLOCK41
Executes a real BTC <-> USD conversion. First generates a quote, then performs the intra-ledger transfer. Returns pre/post balances, delta, quote terms, and transaction ID.
direction — same as swap-quoteCAUTION: Without --dry-run, this moves real funds between wallets. Requires Write scope.
AGENT: This command moves funds between wallets. Always run with
--dry-runfirst, show the quote to the user, and get explicit confirmation before executing without--dry-run.
Quote output:
CODEBLOCK42
Execution output:
CODEBLOCK43
L402 is an HTTP payment protocol: a server returns HTTP 402 with a Lightning invoice, the client pays, and retries the request with a proof-of-payment token. This skill can act as an L402 client.
Supports two L402 formats:
payment_request_url and offers arrayCODEBLOCK44
Probes a URL for L402 payment requirements without paying. Returns the detected format, invoice, and decoded satoshi amount.
url — the URL to probe (required)No API key required for discovery.
Known public L402 endpoints for testing (use specific paths, not root URLs):
https://l402.services/geoip/8.8.8.8 — GeoIP lookup, 1 sat, Lightning Labs formatCODEBLOCK45
Makes an HTTP request. If the server returns 402, automatically parses the challenge, pays the invoice via Blink, caches the token, and retries with the payment proof.
url — URL to access (required)~/.blink/l402-tokens.json)lnInvoiceFeeProbe) before paying to estimate routing fees; warns and continues if the probe fails; adds a feeProbe field to the l402_paid outputRequires Write scope on the API key.
AGENT: Always run with
--dry-runfirst to show the satoshi cost to the user. Confirm the amount and target URL before executing without--dry-run.
CODEBLOCK46
list — show all cached tokens (masks preimage for security)Token cache location: INLINECODE219
l402-discover (Lightning Labs format):
CODEBLOCK47
l402-pay (dry-run):
CODEBLOCK48
l402-pay (after payment):
CODEBLOCK49
l402-pay (after payment, with --probe):
CODEBLOCK50
L402 producer tools let you protect your own API resources behind a Lightning paywall. Issue challenges to clients, then verify their payment proofs before granting access.
Two-step workflow:
blink l402-challenge to create a signed payment challenge and return it with HTTP 402.blink l402-verify to verify the preimage and macaroon signature.Note: End-to-end round-trip testing (challenge → pay → verify) requires two separate Blink accounts. Blink does not allow paying your own invoice (CANTPAYSELF). Use a second account or wallet to pay the challenge invoice during testing.
CODEBLOCK51
Creates a Lightning invoice via Blink and issues a signed macaroon bound to its payment hash. Returns a ready-to-send WWW-Authenticate header.
--amount <sats> — invoice amount in satoshis (required)3600 = 1 hour); controls how long the challenge is valid, not the invoice expiry/api/v1/data); returned tokens will only be valid for this exact pathRequires Write scope on the API key.
Root key for HMAC signing resolves in this order:
BLINK_L402_ROOT_KEY env var (64-char hex, 32 bytes)AGENT: Keep
BLINK_L402_ROOT_KEYor~/.blink/l402-root-keystable across server restarts. A different root key will invalidate all previously issued macaroons.
CODEBLOCK52
Verifies a client-submitted L402 Authorization token. Performs three layers of verification:
SHA-256(preimage) === payment_hash — cryptographic proof the invoice was paid--token <macaroon>:<preimage> — L402 authorization token (colon-separated, from Authorization: L402 <token> header)--token)--token)Exit code 0 when valid: true, exit code 1 when valid: false or on error.
Note: The
--preimagevalue must be a 64-character hex string (32 bytes). Passing a plain string likefake_preimagewill produce an error explaining the format requirement. For testing rejection, use a valid-format but wrong preimage: 64 zeros (0000...0000).
l402-challenge:
CODEBLOCK53
Return this to clients as:
CODEBLOCK54
l402-verify (valid payment):
CODEBLOCK55
l402-verify (invalid — wrong preimage):
CODEBLOCK56
Find L402-gated APIs that agents can pay for and access. Two directory sources:
CODEBLOCK57
No API key required — both directories have free browse APIs.
AGENT: Use
l402-searchto find services before usingl402-pay. Check pricing in the results before paying.
CODEBLOCK58
--report: free, returns endpoints, pricing, consumption instructions--report: 10 sats, returns uptime percentages, probe history, response timesl402.directory)CODEBLOCK59
Prevent runaway spending in autonomous agent workflows with rolling spend limits and domain allowlist.
Env vars take precedence over the config file (~/.blink/budget.json):
| Env var | Config file key | Default | Description |
|---|---|---|---|
| INLINECODE258 | INLINECODE259 | none (unlimited) | Max sats in rolling 1-hour window |
| INLINECODE260 |
dailyLimitSats | none (unlimited) | Max sats in rolling 24-hour window |BLINK_L402_ALLOWED_DOMAINS | allowlist | none (all allowed) | Comma-separated domains for L402 auto-pay |
If no env vars and no config file exist, no limits are enforced (fully backward compatible).
CODEBLOCK60
CODEBLOCK61
INLINECODE264 = min(hourlyRemaining, dailyRemaining) — the actual amount the agent can spend right now.
pay-invoice, pay-lnaddress, pay-lnurl, INLINECODE268l402-pay only — blocks auto-pay to unlisted domains--force bypasses budget: existing --force flag on payment commands skips budget check--dry-run shows budget impact: dry-run output includes a budget field showing remaining budgetAGENT: Before making a payment, check budget status with
blink budget statusto see remaining budget. If budget is exceeded, inform the user and suggest increasing limits withblink budget set.
BLINK_API_KEY in chat messages or files.api.blink.sv (or BLINK_API_URL override) for all GraphQL queries and mutations.ws.blink.sv (or BLINK_WS_URL override) for subscription WebSockets.l402-discover or l402-pay. The Blink API is contacted only when a payment is needed.BLINK_API_KEY is not found in process.env, the client scans ~/.profile, ~/.bashrc, ~/.bash_profile, and ~/.zshrc for a line matching export BLINK_API_KEY=.... Only the value of that specific export is extracted — no other data is read from these files. The environment variable is always checked first.qr command writes temporary PNG files to /tmp/blink_qr_*.png. These are standard image files with no embedded metadata beyond the QR content.l402-pay command writes paid tokens to ~/.blink/l402-tokens.json. This file contains macaroons and preimages for previously-paid L402 services. Use blink l402-store clear to remove all cached tokens. Pass --no-store to disable caching entirely.~/.blink/budget.json and spending log at ~/.blink/spending-log.json. The spending log is auto-pruned (entries older than 25h removed). Use blink budget reset to clear the log.Most scripts are stateless. Exceptions:
l402-pay maintains a token cache at ~/.blink/l402-tokens.json to avoid re-paying for previously-accessed L402 services. Use --no-store to run without any persistence.pay-invoice, pay-lnaddress, pay-lnurl, l402-pay) log spending to ~/.blink/spending-log.json for budget enforcement. This log is auto-pruned and can be cleared with blink budget reset.BLINK_API_URL=https://api.staging.blink.sv/graphql to point at the signet staging environment with test funds.blink price works without an API key; only wallet operations require authentication.l402-pay retrieves the preimage inline from the mutation response (settlementVia.preImage). If the inline preimage is unavailable (e.g. race condition or network issue), it falls back to a transactions query matched by payment hash. If the transaction is not yet indexed, it falls back to a SHA-256(invoice) placeholder, which works with servers using token-based verification but may fail with servers that cryptographically verify the preimage against the payment hash.{baseDir}/scripts/balance.js — Check wallet balances通过 Blink API 操作比特币闪电网络钱包。使代理能够检查余额、通过发票收款、通过闪电网络发送付款、跟踪交易、监控价格,并自动支付 L402 网关保护的网络服务。
Blink 是一个托管式比特币闪电网络钱包,提供 GraphQL API。关键概念:
使用此技能进行具体的钱包操作,而非通用的闪电网络理论。
bash
export BLINKAPIKEY=blink_...
API 密钥作用域:
提示: 从仅读取 + 接收开始。当您需要发送付款时再添加写入。
bash
node {baseDir}/scripts/balance.js
如果您看到包含钱包余额的 JSON,则说明已准备就绪。
要使用 Blink 暂存环境(签章网络)而非真实资金:
bash
export BLINKAPIURL=https://api.staging.blink.sv/graphql
在 dashboard.staging.blink.sv 创建一个暂存 API 密钥。暂存环境使用签章比特币(无实际价值)——非常适合安全地测试支付流程。
如果未设置 BLINKAPIURL,则默认使用生产环境(https://api.blink.sv/graphql)。
脚本按以下顺序自动解析 BLINKAPIKEY:
无需 source ~/.profile 前缀。rc 文件扫描使用针对性正则表达式,仅读取 BLINKAPIKEY 导出行——不会从这些文件中提取其他数据。
如果您已克隆 完整 GitHub 仓库,可以选择安装 blink CLI 命令:
bash
npm install # 安装开发依赖(eslint, prettier)
npm link # 创建全局 blink 命令
blink --help # 验证
注意: npm link 会修改全局 npm 状态。这是可选的——所有功能均可通过直接使用 node {baseDir}/scripts/
多链集团旗下-闲社网
闲社在线客服
关注闲社网微信
闲社网APP
Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1
Powered by Discuz! X5.0 © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com
