This repository was archived by the owner on Mar 22, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 11
This repository was archived by the owner on Mar 22, 2026. It is now read-only.
Nostr event broadcast #109
Copy link
Copy link
Open
Description
Add feature to mercury server that broadcasts it's identity (as a mercury server) to a nostr relay, so can be added to mercury server directories.
Server will need to be configured with a nostr private key (or generate one) and relay server URL.
Then create event with (specified mercury server kind - TBD) and sign and broadcast.
This will be done on a loop with a specified (configured) interval.
e.g. event
{ "id": "unique-event-id", "pubkey": "your-public-key", "created_at": 1690000000, "kind": 30001, "tags": [ ["service", "relay-hosting"], ["features", "websocket,custom-filters,logging"] ], "content": "{\"description\": \"High-performance relay hosting service for Nostr.\"}", "sig": "your-event-signature" } Can use the uses the nostr-sdk crate.
e.g. code:
use nostr_sdk::prelude::*; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { // Step 1: Generate a new key pair let keys = Keys::generate(); println!("Public Key: {}", keys.public_key()); println!("Private Key: {}", keys.secret_key().unwrap()); // Step 2: Create an event advertising a specific service let service_name = "Relay Hosting Service"; let description = "Offering high-performance relay hosting with analytics and filtering."; let tags = vec![ Tag::Custom(vec!["service".to_string(), "relay-hosting".to_string()]), Tag::Custom(vec!["features".to_string(), "analytics,filtering".to_string()]), Tag::Custom(vec!["version".to_string(), "1.0".to_string()]), ]; let event = EventBuilder::new_text_note(description.to_string(), tags) .to_event(&keys)?; println!("Signed Event: {:?}", event); // Step 3: Connect to a relay let relay_url = "wss://relay.damus.io"; // Replace with your desired relay let client = Client::new(&keys); client.add_relay(relay_url, None).await?; client.connect().await; // Step 4: Publish the event match client.send_event(event).await { Ok(event_id) => println!("Event published successfully: {}", event_id), Err(e) => println!("Failed to publish event: {}", e), } // Optional: Keep the connection alive for some time tokio::time::sleep(Duration::from_secs(5)).await; Ok(()) } Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels