nostr-event-builder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nostr Event Builder

Nostr事件构建器

Overview

概述

Construct correct Nostr event structures from natural language descriptions. This skill handles the non-obvious parts: choosing the right kind, building proper tag arrays with correct markers, enforcing NIP-10 vs NIP-22 threading rules, and producing valid event JSON ready for signing.
从自然语言描述构建正确的Nostr事件结构。 该技能负责处理容易出错的部分:选择正确的kind、构建带有正确标记的标签数组、执行NIP-10和NIP-22线程规则,以及生成可供签名的有效事件JSON。

When to Use

适用场景

  • Developer describes what they want to publish on Nostr
  • Building reply threads (NIP-10 kind:1 replies)
  • Commenting on non-note content (NIP-22 kind:1111 comments)
  • Creating or updating user profiles (kind:0 metadata)
  • Constructing any Nostr event and unsure about tag structure
  • Debugging malformed events (wrong markers, missing tags)
Do NOT use when:
  • Implementing relay WebSocket logic (that's relay protocol, not event building)
  • Working with NIP-19 encoding/decoding (bech32 concerns, not event structure)
  • Building subscription filters (REQ messages, not EVENT messages)
  • 开发者描述他们想要在Nostr上发布的内容
  • 构建回复线程(NIP-10 kind:1回复)
  • 对非笔记内容发表评论(NIP-22 kind:1111评论)
  • 创建或更新用户资料(kind:0元数据)
  • 构建任意Nostr事件但不确定标签结构
  • 调试格式错误的事件(标记错误、标签缺失)
不适用场景:
  • 实现中继WebSocket逻辑(属于中继协议范畴,不属于事件构建)
  • 处理NIP-19编码/解码(属于bech32相关内容,不属于事件结构)
  • 构建订阅过滤器(属于REQ消息范畴,不属于EVENT消息)

Workflow

工作流程

1. Identify the Event Kind

1. 确定事件Kind

Ask: "What is the developer trying to publish?"
IntentKindCategoryKey NIP
Post a short text note1RegularNIP-10
Reply to a kind:1 note1RegularNIP-10
Comment on non-kind:1 content1111RegularNIP-22
Set/update user profile0ReplaceableNIP-01
Update follow list3ReplaceableNIP-02
Delete events5RegularNIP-09
Repost a note6RegularNIP-18
React to an event7RegularNIP-25
Publish a long-form article30023AddressableNIP-23
See references/event-kinds.md for full kind-to-structure mapping.
Critical routing rule:
Is the target a kind:1 note?
  YES → Use kind:1 reply with NIP-10 e-tag markers
  NO  → Use kind:1111 comment with NIP-22 uppercase/lowercase tags
询问:「开发者想要发布什么内容?」
意图Kind分类核心NIP
发布短文本笔记1常规NIP-10
回复kind:1笔记1常规NIP-10
评论非kind:1内容1111常规NIP-22
设置/更新用户资料0可替换NIP-01
更新关注列表3可替换NIP-02
删除事件5常规NIP-09
转发笔记6常规NIP-18
对事件作出反应7常规NIP-25
发布长文30023可寻址NIP-23
查看references/event-kinds.md获取完整的kind到结构的映射关系。
关键路由规则:
Is the target a kind:1 note?
  YES → Use kind:1 reply with NIP-10 e-tag markers
  NO  → Use kind:1111 comment with NIP-22 uppercase/lowercase tags

2. Build the Tag Array

2. 构建标签数组

Tags are the hardest part. Follow the tag guide for your kind:
For kind:1 replies (NIP-10):
Direct reply to root (no intermediate replies):
json
{
  "kind": 1,
  "tags": [
    ["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
    ["p", "<root-author-pubkey>"]
  ],
  "content": "Your reply text"
}
Reply to a reply in a thread:
json
{
  "kind": 1,
  "tags": [
    ["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
    [
      "e",
      "<parent-event-id>",
      "<relay-url>",
      "reply",
      "<parent-author-pubkey>"
    ],
    ["p", "<root-author-pubkey>"],
    ["p", "<parent-author-pubkey>"]
  ],
  "content": "Your reply text"
}
For kind:1111 comments (NIP-22):
Top-level comment on a regular event:
json
{
  "kind": 1111,
  "tags": [
    ["E", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["K", "<root-event-kind>"],
    ["P", "<root-author-pubkey>", "<relay-url>"],
    ["e", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["k", "<root-event-kind>"],
    ["p", "<root-author-pubkey>", "<relay-url>"]
  ],
  "content": "Your comment text"
}
Top-level comment on an addressable event (kind 30000-39999):
json
{
  "kind": 1111,
  "tags": [
    ["A", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
    ["K", "<root-event-kind>"],
    ["P", "<root-author-pubkey>", "<relay-url>"],
    ["a", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
    ["e", "<event-id>", "<relay-url>"],
    ["k", "<root-event-kind>"],
    ["p", "<root-author-pubkey>", "<relay-url>"]
  ],
  "content": "Your comment text"
}
Comment on a URL or external identifier:
json
{
  "kind": 1111,
  "tags": [
    ["I", "<url-or-identifier>"],
    ["K", "<identifier-type>"],
    ["i", "<url-or-identifier>"],
    ["k", "<identifier-type>"]
  ],
  "content": "Your comment text"
}
Reply to an existing comment:
json
{
  "kind": 1111,
  "tags": [
    ["E", "<original-root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["K", "<original-root-kind>"],
    ["P", "<root-author-pubkey>"],
    [
      "e",
      "<parent-comment-id>",
      "<relay-url>",
      "<parent-comment-author-pubkey>"
    ],
    ["k", "1111"],
    ["p", "<parent-comment-author-pubkey>"]
  ],
  "content": "Your reply to the comment"
}
See references/tag-guide.md for complete tag semantics.
标签是最复杂的部分,请遵循对应kind的标签指南:
针对kind:1回复(NIP-10):
直接回复根内容(无中间回复):
json
{
  "kind": 1,
  "tags": [
    ["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
    ["p", "<root-author-pubkey>"]
  ],
  "content": "Your reply text"
}
回复线程中的某条回复:
json
{
  "kind": 1,
  "tags": [
    ["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
    [
      "e",
      "<parent-event-id>",
      "<relay-url>",
      "reply",
      "<parent-author-pubkey>"
    ],
    ["p", "<root-author-pubkey>"],
    ["p", "<parent-author-pubkey>"]
  ],
  "content": "Your reply text"
}
针对kind:1111评论(NIP-22):
对常规事件的顶层评论:
json
{
  "kind": 1111,
  "tags": [
    ["E", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["K", "<root-event-kind>"],
    ["P", "<root-author-pubkey>", "<relay-url>"],
    ["e", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["k", "<root-event-kind>"],
    ["p", "<root-author-pubkey>", "<relay-url>"]
  ],
  "content": "Your comment text"
}
对可寻址事件(kind 30000-39999)的顶层评论:
json
{
  "kind": 1111,
  "tags": [
    ["A", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
    ["K", "<root-event-kind>"],
    ["P", "<root-author-pubkey>", "<relay-url>"],
    ["a", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
    ["e", "<event-id>", "<relay-url>"],
    ["k", "<root-event-kind>"],
    ["p", "<root-author-pubkey>", "<relay-url>"]
  ],
  "content": "Your comment text"
}
对URL或外部标识符的评论:
json
{
  "kind": 1111,
  "tags": [
    ["I", "<url-or-identifier>"],
    ["K", "<identifier-type>"],
    ["i", "<url-or-identifier>"],
    ["k", "<identifier-type>"]
  ],
  "content": "Your comment text"
}
回复已有评论:
json
{
  "kind": 1111,
  "tags": [
    ["E", "<original-root-event-id>", "<relay-url>", "<root-author-pubkey>"],
    ["K", "<original-root-kind>"],
    ["P", "<root-author-pubkey>"],
    [
      "e",
      "<parent-comment-id>",
      "<relay-url>",
      "<parent-comment-author-pubkey>"
    ],
    ["k", "1111"],
    ["p", "<parent-comment-author-pubkey>"]
  ],
  "content": "Your reply to the comment"
}
查看references/tag-guide.md获取完整的标签语义说明。

3. Set the Content Field

3. 设置Content字段

Content format depends on the kind:
KindContent Format
0Stringified JSON:
{"name":"...","about":"...","picture":"..."}
1Plaintext (no markdown, no HTML)
5Optional deletion reason text
6Stringified JSON of the reposted event
7
+
(like),
-
(dislike), or emoji
1111Plaintext comment
30023Markdown-formatted article body
内容格式取决于kind:
Kind内容格式
0序列化JSON:
{"name":"...","about":"...","picture":"..."}
1纯文本(无markdown,无HTML)
5可选的删除原因文本
6被转发事件的序列化JSON
7
+
(点赞)、
-
(点踩)或表情符号
1111纯文本评论
30023Markdown格式的文章正文

4. Construct the Complete Event

4. 构建完整事件

Assemble the unsigned event object:
json
{
  "pubkey": "<32-bytes-lowercase-hex-public-key>",
  "created_at": "<unix-timestamp-seconds>",
  "kind": "<integer>",
  "tags": [["..."]],
  "content": "<string>"
}
The
id
is computed as SHA-256 of the serialized form:
json
[0, "<pubkey>", <created_at>, <kind>, <tags>, "<content>"]
Serialization rules:
  • UTF-8 encoding, no whitespace/formatting
  • Escape in content:
    \n
    ,
    \"
    ,
    \\
    ,
    \r
    ,
    \t
    ,
    \b
    ,
    \f
  • All other characters verbatim
The
sig
is a Schnorr signature (secp256k1) of the
id
.
组装未签名的事件对象:
json
{
  "pubkey": "<32-bytes-lowercase-hex-public-key>",
  "created_at": "<unix-timestamp-seconds>",
  "kind": "<integer>",
  "tags": [["..."]],
  "content": "<string>"
}
id
是序列化形式的SHA-256哈希值:
json
[0, "<pubkey>", <created_at>, <kind>, <tags>, "<content>"]
序列化规则:
  • UTF-8编码,无空格/格式
  • 内容中的转义字符:
    \n
    ,
    \"
    ,
    \\
    ,
    \r
    ,
    \t
    ,
    \b
    ,
    \f
  • 所有其他字符保持原样
sig
id
的Schnorr签名(secp256k1)。

5. Validate Before Signing

5. 签名前验证

Checklist before the event is ready:
  • kind
    is correct for the intent
  • All required tags present for this kind
  • e
    tags have correct markers (
    root
    /
    reply
    for kind:1)
  • p
    tags include ALL participants in the thread
  • NIP-10 kind:1 replies only target other kind:1 events
  • NIP-22 kind:1111 comments do NOT target kind:1 events
  • K
    and
    k
    tags present for kind:1111 comments
  • Uppercase tags (E/A/I/K/P) point to root scope in kind:1111
  • Lowercase tags (e/a/i/k/p) point to parent item in kind:1111
  • content
    format matches the kind's requirements
  • created_at
    is a Unix timestamp in seconds (not milliseconds)
  • All hex values are 32-byte lowercase
事件准备就绪前的检查清单:
  • kind
    符合发布意图
  • 该kind所需的所有标签都已存在
  • e
    标签带有正确的标记(kind:1对应
    root
    /
    reply
  • p
    标签包含线程中的所有参与者
  • NIP-10 kind:1回复仅针对其他kind:1事件
  • NIP-22 kind:1111评论不针对kind:1事件
  • kind:1111评论包含
    K
    k
    标签
  • kind:1111中的大写标签(E/A/I/K/P)指向根范围
  • kind:1111中的小写标签(e/a/i/k/p)指向父项
  • content
    格式符合对应kind的要求
  • created_at
    是秒级Unix时间戳(不是毫秒级)
  • 所有十六进制值都是32字节小写

Common Mistakes

常见错误

MistakeWhy It BreaksFix
Using kind:1 to reply to a kind:30023 articleNIP-10 kind:1 replies MUST only reply to other kind:1 eventsUse kind:1111 (NIP-22 comment) for non-kind:1 targets
Using kind:1111 to reply to a kind:1 noteNIP-22 comments MUST NOT reply to kind:1Use kind:1 with NIP-10 e-tag markers
Missing
root
marker on e tags in kind:1
Clients can't reconstruct the thread treeAlways use marked e tags:
["e", "<id>", "<relay>", "root"]
Only one e tag with
reply
marker (no
root
)
Direct replies to root need
root
marker, not
reply
Single e tag = use
root
marker only
Missing p tags for thread participantsUsers don't get notified of repliesInclude p tags for ALL pubkeys in the thread
Lowercase e/k/p tags for root scope in kind:1111Root scope MUST use uppercase E/K/P tagsUppercase = root scope, lowercase = parent item
Missing K or k tags in kind:1111Both are REQUIRED by NIP-22Always include
["K", "<root-kind>"]
and
["k", "<parent-kind>"]
created_at
in milliseconds
Nostr uses seconds, not millisecondsUse
Math.floor(Date.now() / 1000)
Content as object instead of string for kind:0Content must be stringified JSONUse
JSON.stringify({name: "...", ...})
Missing
d
tag on addressable events (30000-39999)
Relay can't address the event properlyAlways include
["d", "<identifier>"]
Positional e tags without markersDeprecated; creates ambiguity in thread reconstructionAlways use marked e tags with
root
/
reply
错误出错原因修复方案
使用kind:1回复kind:30023文章NIP-10 kind:1回复必须仅回复其他kind:1事件对非kind:1目标使用kind:1111(NIP-22评论)
使用kind:1111回复kind:1笔记NIP-22评论禁止回复kind:1内容使用带有NIP-10 e标签标记的kind:1
kind:1的e标签缺失
root
标记
客户端无法重建线程树始终使用带标记的e标签:
["e", "<id>", "<relay>", "root"]
仅存在一个带有
reply
标记的e标签(无
root
标记)
直接回复根内容需要
root
标记,而非
reply
单个e标签 = 仅使用
root
标记
缺失线程参与者对应的p标签用户无法收到回复通知包含线程中所有公钥对应的p标签
kind:1111中根范围使用小写e/k/p标签根范围必须使用大写E/K/P标签大写 = 根范围,小写 = 父项
kind:1111中缺失K或k标签NIP-22要求两者都必须存在始终包含
["K", "<root-kind>"]
["k", "<parent-kind>"]
created_at
使用毫秒级时间戳
Nostr使用秒级时间戳,而非毫秒级使用
Math.floor(Date.now() / 1000)
kind:0的content是对象而非字符串content必须是序列化JSON使用
JSON.stringify({name: "...", ...})
可寻址事件(30000-39999)缺失
d
标签
中继无法正确寻址事件始终包含
["d", "<identifier>"]
使用不带标记的位置型e标签已废弃;会在线程重建时产生歧义始终使用带有
root
/
reply
标记的e标签

Kind Category Quick Reference

Kind分类快速参考

RangeCategoryBehavior
1000-9999, 4-44, 1, 2RegularStored by relays, all kept
10000-19999, 0, 3ReplaceableLatest per pubkey+kind kept
20000-29999EphemeralNot stored by relays
30000-39999AddressableLatest per pubkey+kind+d-tag kept
范围分类行为
1000-9999, 4-44, 1, 2常规由中继存储,全部保留
10000-19999, 0, 3可替换仅保留每个pubkey+kind对应的最新版本
20000-29999临时不会被中继存储
30000-39999可寻址仅保留每个pubkey+kind+d-tag对应的最新版本

Example: Complete Event Construction

示例:完整事件构建

User says: "I want to reply to my friend's note in an existing thread"
Step 1 — Identify kind: Replying to a kind:1 note → use kind:1 (NIP-10)
Step 2 — Determine thread position: This is a reply to a reply (not the root), so we need both
root
and
reply
e tags.
Step 3 — Build the event:
json
{
  "pubkey": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
  "created_at": 1709827200,
  "kind": 1,
  "tags": [
    ["e", "aaa111...", "wss://relay.example.com", "root", "f7234bd4..."],
    ["e", "bbb222...", "wss://relay.example.com", "reply", "93ef2eba..."],
    ["p", "f7234bd4...", "wss://relay.example.com"],
    ["p", "93ef2eba...", "wss://relay.example.com"]
  ],
  "content": "Great point! I totally agree with this take."
}
Step 4 — Validate: Root e tag has
root
marker ✓, reply e tag has
reply
marker ✓, p tags include both the root author and the parent author ✓, content is plaintext ✓.
用户说:「我想在已有线程中回复我朋友的笔记」
步骤1 — 确定kind: 回复kind:1笔记 → 使用kind:1(NIP-10)
步骤2 — 确定线程位置: 这是对回复的回复(不是根内容),所以我们需要同时带有
root
reply
标记的e标签。
步骤3 — 构建事件:
json
{
  "pubkey": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
  "created_at": 1709827200,
  "kind": 1,
  "tags": [
    ["e", "aaa111...", "wss://relay.example.com", "root", "f7234bd4..."],
    ["e", "bbb222...", "wss://relay.example.com", "reply", "93ef2eba..."],
    ["p", "f7234bd4...", "wss://relay.example.com"],
    ["p", "93ef2eba...", "wss://relay.example.com"]
  ],
  "content": "Great point! I totally agree with this take."
}
步骤4 — 验证: 根e标签带有
root
标记 ✓,回复e标签带有
reply
标记 ✓,p标签包含根作者和父回复作者 ✓,内容为纯文本 ✓。