NIP-65: Relay List Metadata
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.
TODO
The simplest 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 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.sign_with_keys(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.sign_with_keys(keys)
# Print event as json
print(f" Event: {event.as_json()}")
The simplest way to create relay metadata events is via the relayList()
method and EventBuilder
class. To do this we can simply use the RelayListItem
class to create a list of relay objects containing the relay URL and READ/WRITE, which is set using the RelayMetadata
class.
Note that where no read or write value is specified (e.g. null
), these should be handled as both read and write by clients (as indicated in the NIP-65 specification).
// Create relay list
let relays = [
new RelayListItem("wss://relay.damus.io", RelayMetadata.Read),
new RelayListItem("wss://relay.primal.net", RelayMetadata.Write),
new RelayListItem("wss://relay.nostr.band")
];
// Build/sign event
let builder = EventBuilder.relayList(relays);
let event = builder.signWithKeys(keys);
// Print event as json
console.log(` Event: ${event.asJson()}`);
As an alternative approach, the Tag
class and relayMetadata()
method can be used to create individual tag objects for inclusion in a purpose built kind:10002
event.
// Create relay metadata tags
let tag1 = Tag.relayMetadata("wss://relay.damus.io", RelayMetadata.Read);
let tag2 = Tag.relayMetadata("wss://relay.primal.net", RelayMetadata.Write);
let tag3 = Tag.relayMetadata("wss://relay.nostr.band");
// Build/sign event
let kind = new Kind(10002);
let content = "";
let tags = [tag1, tag2, tag3];
builder = new EventBuilder(kind, content, tags);
event = builder.signWithKeys(keys);
// Print event as json
console.log(` Event: ${event.asJson()}`);
TODO
TODO
TODO