NIP-65

Either the Event Builder struct and associated relay_list() function, or, the Tag struct and associated relay_metadata() function, can be used to construct NIP-65 compliant events (kind:10002), which are designed to advertise user's preferred relays from which content can be retrieved and/or published.

Relay List Metadata (NIP-65)

Rust

TODO

Python

The simpleist way to create relay metadata events is via the relay_list() method and EventBuilder class. To do this we pass the method a dictionary containing the relay URL (key) and READ/WRITE (value), which is set using the RelayMetadata class.

Note that the where no read or write value is specified (e.g. None), these should be handled as both read and write by clients (as indicated in the NIP-65 specification).

    # Create relay dictionary
    relays_dict = {
        "wss://relay.damus.io": RelayMetadata.READ,
        "wss://relay.primal.net": RelayMetadata.WRITE,
        "wss://relay.nostr.band": None
    }
    
    # Build/sign event
    builder = EventBuilder.relay_list(relays_dict)
    event = builder.to_event(keys)

    # Print event as json
    print(f" Event: {event.as_json()}")

As an alternative approach, the Tag class and relay_metadata() method can be used to create individual tag objects for inclusion in a purpose built kind:10002 event.

    # Create relay metadata tags
    tag1 = Tag.relay_metadata("wss://relay.damus.io", RelayMetadata.READ)
    tag2 = Tag.relay_metadata("wss://relay.primal.net", RelayMetadata.WRITE)
    tag3 = Tag.relay_metadata("wss://relay.nostr.band", None)

    # Build/sign event
    kind = Kind(10002)
    content = ""
    tags = [tag1,tag2,tag3]
    builder = EventBuilder(kind,content,tags)
    event = builder.to_event(keys)

    # Print event as json
    print(f" Event: {event.as_json()}")
JavaScript

TODO

Kotlin

TODO

Swift

TODO