← Todos los NIPs

NIP-C0

Fragmentos de código

BorradorEventos

Comparte código como eventos kind 1337: el content es el código, y los tags indican el lenguaje, el nombre de archivo, la licencia, las dependencias y el repositorio de origen.

De un vistazo

Estado
En uso, pero todavía puede cambiar.
Kinds
Tags
  • description
  • extension
  • l
  • license
  • name
  • repo
  • runtime
Último cambio
30 dic 2025

Pruébalo

Edita el formulario o el JSON: ambos se mantienen sincronizados, la insignia indica si el resultado es válido y, al tocar cualquier campo, se explica qué hace.

Ejemplos
Válido 1 nota

Aún sin firmar · Solo claves de demo. Las claves secretas de estos personajes son públicas a propósito.

Formulario
1 ene 2025, 0:00 UTC

Contenido

El código en sí.

Tags

  1. l Recomendado

    Lenguaje de programación.

  2. name Opcional

    Nombre del fragmento, normalmente un nombre de archivo.

  3. extension Opcional

    Extensión de archivo, usada para resaltar y descargar el fragmento.

  4. description Opcional

    Qué hace el código, en una frase.

  5. runtime Opcional

    Runtime o entorno para el que se escribió.

  6. license Opcional

    Licencia del código. Repítelo para varias licencias.

  7. repo Opcional

    De dónde viene el código.

Añadir tag

Cómo funciona este NIP

Paso 1 de 5

El código es el content

Pon el fragmento en el content tal como está escrito. Los clientes conservan los espacios y la indentación y ofrecen copiarlo con un clic.

En el curso

Ningún capítulo del curso cubre este NIP todavía. El editor de arriba es la forma más rápida de empezar.

Se basa en

Ver también

Especificación

El texto de las especificaciones se cita en inglés del repositorio nostr-protocol/nips. Nuestras explicaciones y la interfaz están traducidas. Código fuente en GitHub en el commit 0046368

Leer la especificación466 palabras, citadas del repositorio en el commit 0046368.

Abstract

This NIP defines a new event kind for sharing and storing code snippets. Unlike regular text notes (kind:1), code snippets have specialized metadata like language, extension, and other code-specific attributes that enhance discoverability, syntax highlighting, and improved user experience.

Event Kind

This NIP defines kind:1337 as a code snippet event.

The .content field contains the actual code snippet text.

Optional Tags

  • l - Programming language name (lowercase). Examples: "javascript", "python", "rust"
  • name - Name of the code snippet, commonly a filename. Examples: "hello-world.js", "quick-sort.py"
  • extension - File extension (without the dot). Examples: "js", "py", "rs"
  • description - Brief description of what the code does
  • runtime - Runtime or environment specification (e.g., "node v18.15.0", "python 3.11")
  • license - License under which the code (along with any related data contained within the event, when available, such as the description) is shared. This MUST be a standard SPDX short identifier (e.g., "MIT", "GPL-3.0-or-later", "Apache-2.0") when available. An additional parameter containing a reference to the actual text of the license MAY be provided. This tag can be repeated, to indicate multi-licensing, allowing recipients to use the code under any license of choosing among the referenced ones
  • dep - Dependency required for the code to run (can be repeated)
  • repo - Reference to a repository where this code originates. This MUST be either a standard URL or, alternatively, the address of a NIP-34 Git repository announcement event in the form "30617:<32-bytes hex a pubkey>:<d tag value>". If a repository announcement is referenced, a recommended relay URL where to find the event should be provided as an additional parameter

Format

{
  "id": "<32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>",
  "pubkey": "<32-bytes lowercase hex-encoded public key of the event creator>",
  "created_at": <Unix timestamp in seconds>,
  "kind": 1337,
  "content": "function helloWorld() {\n  console.log('Hello, Nostr!');\n}\n\nhelloWorld();",
  "tags": [
    ["l", "javascript"],
    ["extension", "js"],
    ["name", "hello-world.js"],
    ["description", "A basic JavaScript function that prints 'Hello, Nostr!' to the console"],
    ["runtime", "node v18.15.0"],
    ["license", "MIT"],
    ["repo", "https://github.com/nostr-protocol/nostr"]
  ],
  "sig": "<64-bytes signature of the id>"
}

Client Behavior

Clients that support this NIP SHOULD:

  1. Display code snippets with proper syntax highlighting based on the language.
  2. Allow copying the full code snippet with a single action.
  3. Render the code with appropriate formatting, preserving whitespace and indentation.
  4. Display the language and extension prominently.
  5. Provide "run" functionality for supported languages when possible.
  6. Display the description (if available) as part of the snippet presentation.

Clients MAY provide additional functionality such as:

  1. Code editing capabilities
  2. Forking/modifying snippets
  3. Creating executable environments based on the runtime/dependencies
  4. Downloading the snippet as a file using the provided extension
  5. Sharing the snippet with attribution