Nostr (nak)
Overview
Use
nak for all Nostr actions: publish notes, reply in threads, and query relays for replies/mentions. Default relay:
wss://relay.primal.net unless the user specifies another.
Install / Update nak
- - Repo: https://github.com/fiatjaf/nak
- Install (script): INLINECODE2
- Update: re-run the install script above (it installs latest)
- Tip: review the script before running if you want to audit what it does.
Onboarding (keys)
- - Generate a new key:
nak key generate (prints nsec + npub) - Save the secret: store
NOSTR_SECRET_KEY in a shell profile or a local .env with restricted permissions.
- Example:
export NOSTR_SECRET_KEY="nsec1..."
- Optional:
chmod 600 .env if you store it locally.
- Prefer env vars over inline
--sec in commands.
Quick Start (common tasks)
- - Post a note: INLINECODE9
- Reply to a note: include
root and reply tags (see below) - Check replies: INLINECODE12
- Check mentions: INLINECODE13
Workflow: Posting & Replies
1) Create a new note
CODEBLOCK0
2) Reply to a reply (correct threading)
Always include both
root and
reply tags so clients display it as a reply:
- -
root = original top‑level note id - INLINECODE17 = the specific note you’re replying to
Use -t e="<id>;<relay>;root" and -t e="<id>;<relay>;reply".
Example:
CODEBLOCK1
3) Check for replies to a note
CODEBLOCK2
4) Check mentions of your pubkey
CODEBLOCK3
Conventions
- - Default relay: INLINECODE20
- Prefer
NOSTR_SECRET_KEY env var instead of inline --sec. - When tagging users, include
-p <npub/hex>. - For human-facing links, encode with
nak encode nevent ... and format as https://primal.net/e/<nevent>.
References
- - Use
nak event --help and nak req --help for flag details.
Nostr (nak)
概述
使用 nak 执行所有 Nostr 操作:发布笔记、回复线程、查询中继获取回复/提及。默认中继:wss://relay.primal.net,除非用户指定其他中继。
安装/更新 nak
- - 仓库: https://github.com/fiatjaf/nak
- 安装(脚本): curl -sSL https://raw.githubusercontent.com/fiatjaf/nak/master/install.sh | sh
- 更新: 重新运行上述安装脚本(会安装最新版本)
- 提示: 如需审计脚本内容,请在运行前查看脚本。
入门(密钥)
- - 生成新密钥: nak key generate(输出 nsec + npub)
- 保存密钥: 将 NOSTRSECRETKEY 存储在 shell 配置文件或本地权限受限的 .env 文件中。
- 示例: export NOSTR
SECRETKEY=nsec1...
- 可选: 若本地存储,执行 chmod 600 .env
- 优先使用环境变量,而非在命令中内联使用 --sec。
快速入门(常见任务)
- - 发布笔记: nak event -k 1 --sec $NOSTRSECRETKEY -c ... <中继地址>
- 回复笔记: 包含 root 和 reply 标签(见下文)
- 查看回复: nak req -k 1 -e <事件ID> -l <中继地址>
- 查看提及: nak req -k 1 -p <你的公钥十六进制> -l <中继地址>
工作流程:发布与回复
1) 创建新笔记
bash
nak event -k 1 --sec $NOSTR
SECRETKEY -c <内容> wss://relay.primal.net
2) 回复一条回复(正确线程)
始终同时包含 root 和 reply 标签,以便客户端正确显示为回复:
- - root = 原始顶层笔记 ID
- reply = 你正在回复的具体笔记
使用 -t e=;<中继地址>;root 和 -t e=;<中继地址>;reply。
示例:
bash
nak event -k 1 --sec $NOSTRSECRETKEY \
-t e=;wss://relay.primal.net;root \
-t e=;wss://relay.primal.net;reply \
-p <其他公钥十六进制> \
-c <回复内容> \
wss://relay.primal.net
3) 查看笔记的回复
bash
nak req -k 1 -e
-l 20 wss://relay.primal.net
4) 查看你的公钥的提及
bash
nak req -k 1 -p <你的公钥十六进制> -l 20 wss://relay.primal.net
约定
- - 默认中继: wss://relay.primal.net
- 优先使用 NOSTRSECRETKEY 环境变量,而非内联 --sec。
- 标记用户时,包含 -p 。
- 面向用户的链接,使用 nak encode nevent ... 编码,格式为 https://primal.net/e/。
参考
- - 使用 nak event --help 和 nak req --help 查看参数详情。