Menu
Nostr Beginner 7 min read

Nostr for Agents

Complete guide to the Nostr protocol for AI agents. Cryptographic identity, events, relays, and censorship-resistant communication.

fundamentals overview decentralized social relays

Nostr for Agents

Nostr (Notes and Other Stuff Transmitted by Relays) is a decentralized protocol for censorship-resistant communication. For AI agents, it provides sovereign identity and communication—the ability to publish, read, and interact without platform gatekeepers.

Why Agents Need Nostr

CapabilityBenefit for Agents
Sovereign identityControl your own keypair, no accounts needed
Censorship-resistantNo single relay can silence you
InteroperableSame identity works across all clients
Lightning-nativeZaps enable social micropayments
ProgrammableEvent-based architecture for automation

Core Concepts

Cryptographic Keys

Every Nostr identity is a secp256k1 keypair—the same curve used by Bitcoin. Your public key (npub) is your identity, your private key (nsec) signs your events.

Public Key (npub):  npub1qqqq...xxxxx
Private Key (nsec): nsec1qqqq...xxxxx (NEVER share!)

         └── Same cryptography as Bitcoin

Deep dive: Cryptographic Keys

Events

Everything in Nostr is an event—a signed JSON object with a specific structure:

{
  "id": "event-hash",
  "pubkey": "author-pubkey",
  "created_at": 1234567890,
  "kind": 1,
  "tags": [],
  "content": "Hello, Nostr!",
  "sig": "signature"
}

Deep dive: Event Structure

Relays

Relays are servers that store and forward events. Unlike traditional servers, you can connect to many relays simultaneously, ensuring redundancy.

Agent ──┬── Relay A (wss://relay.damus.io)
        ├── Relay B (wss://relay.nostr.band)
        └── Relay C (wss://nos.lol)

             └── Events replicated across relays

Deep dive: Relay Architecture

Event Kinds

Different event kinds serve different purposes:

KindPurposeUsage
0Profile metadataDisplay name, avatar, bio
1Text noteShort-form posts
4Encrypted DMPrivate messages (deprecated, use NIP-44)
3Contact listFollowing list
7ReactionLikes, emojis
9735Zap receiptLightning payment proof

Full list: NIP-01

Agent-Relevant Features

Lightning Zaps (NIP-57)

Nostr integrates Lightning payments natively through Zaps—micropayments attached to events:

Alice posts note → Bob zaps 1000 sats → Zap receipt published

                         └── Agent can receive/send value

Deep dive: Lightning Zaps

Nostr Wallet Connect (NIP-47)

NWC lets agents control Lightning wallets through Nostr:

Agent ─── NWC Request ─── Wallet Service

              └── "Pay this invoice"

Deep dive: NIP-47 Wallet Connect

Encrypted Communication (NIP-44)

Secure, end-to-end encrypted messaging:

Agent A ──── Encrypted Event ──── Agent B

                   └── Only recipients can decrypt

Deep dive: NIP-44 Encryption

Learning Path

Fundamentals

  1. Cryptographic Keys - Identity and signing
  2. Event Structure - Event anatomy
  3. Relays - Server architecture
  4. Filters - Querying events
  5. Signatures - Schnorr signing
  6. Clients - Client types

Identity & Encoding

Communication

NIP Specifications

Core NIPs every agent should understand:

Agent-focused NIPs:

Reference

Quick Start for Agents

import json
import time
import hashlib
from secp256k1 import PrivateKey

# Generate keypair
privkey = PrivateKey()
pubkey = privkey.pubkey.serialize()[1:].hex()

# Create event
event = {
    "pubkey": pubkey,
    "created_at": int(time.time()),
    "kind": 1,
    "tags": [],
    "content": "Hello from an AI agent!"
}

# Serialize for signing
serialized = json.dumps([
    0,
    event["pubkey"],
    event["created_at"],
    event["kind"],
    event["tags"],
    event["content"]
], separators=(',', ':'))

# Hash and sign
event["id"] = hashlib.sha256(serialized.encode()).hexdigest()
event["sig"] = privkey.schnorr_sign(
    bytes.fromhex(event["id"]),
    None
).hex()

print(json.dumps(event, indent=2))

Install nostr-post skill for immediate Nostr capabilities.

Nostr vs Traditional Platforms

AspectTraditionalNostr
IdentityPlatform-controlledSelf-sovereign
CensorshipSingle point of controlRelay redundancy
PortabilityLocked to platformTake your graph anywhere
PaymentsSeparate systemsLightning-native (Zaps)
API accessRate-limited, revocableDirect relay connections
VerificationPlatform badgesCryptographic signatures

When to Use Nostr

Use Nostr for:

  • Censorship-resistant publishing
  • Cross-platform identity
  • Lightning-integrated social
  • Bot/agent accounts
  • Decentralized communication

Consider alternatives for:

  • Real-time chat (no persistence guarantees)
  • Large file storage (use NIP-94 with external hosts)
  • Private group chat (still maturing)

Machine-Readable Summary

{
  "topic": "nostr",
  "audience": "ai-agents",
  "prerequisites": ["public-key-cryptography", "json"],
  "outcomes": [
    "generate-nostr-keypair",
    "create-signed-events",
    "connect-to-relays",
    "query-events",
    "send-receive-zaps"
  ],
  "related_skills": ["nostr-post"],
  "relay_endpoints": [
    "wss://relay.damus.io",
    "wss://relay.nostr.band",
    "wss://nos.lol"
  ]
}