Skip to content

Tag: d

Overview

The "d" tag is used to provide a unique identifier for addressable events in the Nostr protocol. It serves as the third component of the triple (kind, pubkey, d-tag) that uniquely identifies an addressable event, enabling updates to specific pieces of content while maintaining their identity.

Specification

PropertyValue
Tag Named
Defined inNIP-01
Required forAddressable events (kinds 30000-39999)

Format

["d", "<unique-identifier-string>"]

Usage Description

The "d" tag provides a unique identifier for an addressable event. Unlike regular replaceable events that are identified only by their kind and pubkey, addressable events require this third component to allow users to maintain multiple updatable pieces of content of the same kind.

When a new event is published with the same kind, pubkey, and d-tag value as an existing event, it replaces the previous event. Only the latest version should be stored by relays, while older versions may be discarded.

The value of the d-tag can be any string, but it is recommended to use a value that is:

  1. Meaningful to the content (like a slug)
  2. Short and human-readable
  3. URL-safe (using only alphanumeric characters, hyphens, and underscores)
  4. Unique within the scope of a user's events of a particular kind

The d-tag is most commonly used with addressable kinds in the 30000-39999 range, such as kind 30023 for long-form content.

Examples

Basic Example for Long-form Content

json
["d", "my-first-article"]

Example in a Full Event

json
{
  "kind": 30023,
  "created_at": 1675642635,
  "content": "This is my article about Nostr...",
  "tags": [
    ["d", "introduction-to-nostr"],
    ["title", "Introduction to Nostr"]
  ],
  "pubkey": "a695f6b60119d9521934a691347d9f78e8770b56da16bb255ee286ddf9fda919",
  "id": "..."
}

Client Behavior

Clients should:

  1. Include a "d" tag with a unique identifier when creating addressable events
  2. When updating an existing addressable event, use the same d-tag value to ensure it replaces the previous version
  3. Understand that two events with the same kind, pubkey, and d-tag value represent different versions of the same content, with the most recent one being the current version
  4. Use the d-tag value when constructing "a" tags to reference addressable events

Relay Behavior

Relays should:

  1. For addressable events (kinds 30000-39999), index them by the combination of kind, pubkey, and the first value in their "d" tag
  2. When receiving a new event with the same kind, pubkey, and d-tag value as an existing event, replace the older version with the newer one
  3. Support filtering by d-tag values using the #d filter parameter in subscription requests
  4. For a filter like {"kinds": [30023], "authors": [<hex-key>], "#d": ["introduction-to-nostr"]}, return the latest event that matches all criteria

References

Notes

The "d" tag is essential for the implementation of addressable events, which allow users to maintain multiple updatable pieces of content of the same kind. Without the d-tag, users would be limited to a single updatable event per kind (as with regular replaceable events).

The most common use case for the d-tag is in long-form content (kind 30023), where it allows users to maintain a collection of articles, each uniquely identified by its d-tag value. The d-tag value often serves as a slug or permalink for the article.

While the d-tag can contain any string value, using URL-friendly values that relate to the content helps with organization and sharing. For example, a blog post titled "Introduction to Nostr" might use a d-tag value of "introduction-to-nostr".