Nutshell (Cashu CLI)
Nutshell is a command-line wallet for Cashu, an ecash protocol for Bitcoin. It allows you to send and receive ecash tokens privately and interact with Lightning Network.
Installation
This skill requires the cashu CLI. Install it via pipx (recommended) or pip:
CODEBLOCK0
Ensure the binary path is in your PATH.
Environment Configuration (Required)
The CLI requires two environment variables to function correctly:
- 1.
CASHU_DIR: Directory for wallet data (typically ~/.cashu). - INLINECODE6 (or
MINT_HOST): The URL of the Cashu mint you want to use.
Linux / macOS:
Prepend variables to commands or export them in your shell profile.
CODEBLOCK1
Windows (PowerShell):
CODEBLOCK2
CLI Usage
All examples below assume CASHU_DIR and MINT_URL are set. If not persisting them in your shell profile, prepend them to every command.
Agent Tip: Always use the --yes (or -y) flag to skip interactive prompts and confirmations. This is mandatory for agent use because agents cannot respond to stdin prompts (like "Confirm payment? [y/N]"); omitting it will cause the command to hang and time out.
Balance & Info
CODEBLOCK3
Sending & Receiving
Send Cashu tokens (ecash):
CODEBLOCK4
Receive Cashu tokens:
CODEBLOCK5
Lightning Network
Pay a Lightning Invoice (melt):
CODEBLOCK6
Pay a Lightning Address (LNURL):
CODEBLOCK7
Create a Lightning Invoice (mint):
CODEBLOCK8
Lightning Address (LNURL)
Manage your Nostr Lightning Address (e.g., user@npubx.cash) to receive payments.
CODEBLOCK9
Paying Cashu 402s (Agentic Pattern)
Cashu-enabled APIs may return a 402 Payment Required error with a payment request in the X-Cashu header. This is common for metered APIs or paid endpoints.
The flow:
- 1. Make your HTTP request
- If you get a 402 with
X-Cashu: creqA... header, extract the payment request - (Optional) Decode it to check accepted mints: INLINECODE15
- Pay it: INLINECODE16
- Get the token from the response
- Retry the original request, including the token in the
X-Cashu header
Mint compatibility: Payment requests may encode specific mints from which ecash is accepted. If you try to pay with a wallet backed by a mint not in the allowed list, it will error. Use cashu decode <creq> to see which mints are accepted before attempting payment.
Example:
CODEBLOCK10
This pattern is agentic-friendly: handle 402 automatically, pay, retry — just like handling rate limits or auth redirects.
Advanced
CODEBLOCK11
Configuration
Nutshell uses a .env file inside CASHU_DIR for additional configuration.
If MINT_URL is not provided, it may default to a public test mint or fail. Always specify your trusted mint.
Notes
- - Tokens are large strings starting with
cashuA... (V3) or cashuB... (V4). - Ensure you back up your mnemonic if using significant funds (see
cashu info).
Contributing
Open issues or contribute at https://github.com/cashubtc/nutshell
Nutshell (Cashu CLI)
Nutshell 是 Cashu 的命令行钱包,Cashu 是比特币的电子现金协议。它允许你私密地发送和接收电子现金代币,并与闪电网络交互。
安装
此技能需要 cashu CLI。通过 pipx(推荐)或 pip 安装:
bash
推荐(隔离环境)
pipx install cashu
替代方案(系统/用户全局)
pip install cashu
确保二进制文件路径在你的 PATH 中。
环境配置(必需)
CLI 需要两个环境变量才能正常运行:
- 1. CASHUDIR:钱包数据目录(通常为 ~/.cashu)。
- MINTURL(或 MINT_HOST):你想使用的 Cashu 铸币厂 URL。
Linux / macOS:
在命令前添加变量,或在 shell 配置文件中导出它们。
bash
单条命令
CASHU
DIR=~/.cashu MINTURL=https://mint.example.com cashu balance
持久化(添加到 ~/.bashrc 或 ~/.zshrc)
export CASHU_DIR=~/.cashu
export MINT_URL=https://mint.example.com
Windows (PowerShell):
powershell
$env:CASHU_DIR = $HOME\.cashu
$env:MINT_URL = https://mint.example.com
cashu balance
CLI 使用
以下所有示例均假设已设置 CASHUDIR 和 MINTURL。如果未在 shell 配置文件中持久化它们,请在每条命令前添加它们。
代理提示: 始终使用 --yes(或 -y)标志来跳过交互式提示和确认。这对于代理使用是强制性的,因为代理无法响应 stdin 提示(例如“确认支付?[y/N]”);省略该标志将导致命令挂起并超时。
余额与信息
bash
检查钱包余额
CASHU
DIR=~/.cashu MINTURL=
cashu --yes balance
检查待处理代币
CASHUDIR=~/.cashu MINTURL= cashu --yes pending
获取钱包信息
CASHUDIR=~/.cashu MINTURL= cashu --yes info
列出钱包
CASHUDIR=~/.cashu MINTURL= cashu --yes wallets
发送与接收
发送 Cashu 代币(电子现金):
bash
发送金额(生成一个可共享的代币字符串)
CASHUDIR=~/.cashu MINTURL= cashu --yes send
示例:CASHUDIR=~/.cashu MINTURL=https://8333.space:3338 cashu --yes send 100
接收 Cashu 代币:
bash
接收一个代币字符串
CASHUDIR=~/.cashu MINTURL= cashu --yes receive
闪电网络
支付闪电发票(熔铸):
bash
支付一张发票
CASHUDIR=~/.cashu MINTURL= cashu --yes pay
支付闪电地址(LNURL):
bash
支付 LNURL/闪电地址(自动解析发票)
CASHUDIR=~/.cashu MINTURL= cashu --yes pay
示例:CASHUDIR=~/.cashu MINTURL= cashu --yes pay user@npubx.cash 100
创建闪电发票(铸币):
bash
创建一张发票以接收资金到钱包
CASHUDIR=~/.cashu MINTURL= cashu --yes invoice
闪电地址 (LNURL)
管理你的 Nostr 闪电地址(例如 user@npubx.cash)以接收付款。
bash
创建(或显示)你的静态闪电地址
CASHUDIR=~/.cashu MINTURL= cashu --yes lnurl create
检查发送到你的地址的待处理付款
CASHUDIR=~/.cashu MINTURL= cashu --yes lnurl check
铸币(认领)待处理付款
CASHUDIR=~/.cashu MINTURL= cashu --yes lnurl mint
支付 Cashu 402 错误(代理模式)
支持 Cashu 的 API 可能会返回 402 Payment Required 错误,并在 X-Cashu 标头中包含支付请求。这对于按量计费的 API 或付费端点很常见。
流程:
- 1. 发起你的 HTTP 请求
- 如果收到带有 X-Cashu: creqA... 标头的 402 错误,提取支付请求
- (可选)解码它以检查接受的铸币厂:cashu decode request>
- 支付它:cashu --yes pay request>
- 从响应中获取代币
- 重试原始请求,在 X-Cashu 标头中包含代币
铸币厂兼容性: 支付请求可能编码了接受电子现金的特定铸币厂。如果你尝试使用由不在允许列表中的铸币厂支持的钱包进行支付,将会出错。在尝试支付前,使用 cashu decode 查看哪些铸币厂被接受。
示例:
bash
1. 初始请求(返回 402)
curl -s -i https://api.example.com/data
响应包含:
HTTP/1.1 402 Payment Required
X-Cashu: creqA1...
2. 支付支付请求
CASHUDIR=~/.cashu MINTURL= cashu --yes pay creqA1...
返回类似 cashuA... 的代币
3. 使用代币重试
curl -s -H X-Cashu: cashuA... https://api.example.com/data
这种模式对代理友好:自动处理 402 错误,支付,重试——就像处理速率限制或身份验证重定向一样。
高级
bash
销毁已花费的代币
CASHUDIR=~/.cashu MINTURL= cashu --yes burn
查看所有发票
CASHUDIR=~/.cashu MINTURL= cashu --yes invoices
配置
Nutshell 使用 CASHU_DIR 内的 .env 文件进行额外配置。
如果未提供 MINT_URL,它可能默认为公共测试铸币厂或失败。始终指定你信任的铸币厂。
注意事项
- - 代币是以 cashuA...(V3)或 cashuB...(V4)开头的大字符串。
- 如果使用大量资金,请确保备份你的助记词(参见 cashu info)。
贡献
提出问题或在 https://github.com/cashubtc/nutshell 贡献代码。