1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use anya_core::enterprise::{NostrClient, NostrConfig, NostrUserProfile};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Subscribe with existing key
let profile = NostrUserProfile::subscribe_with_key(
"nsec1...", // Replace with your private key
None, // Use default relays
)
.await?;
// Initialize Nostr client
let config = NostrConfig {
private_key: profile.to_nsec()?,
relays: vec![
"wss://relay.damus.io".to_string(),
"wss://relay.nostr.info".to_string(),
"wss://nostr-pub.wellorder.net".to_string(),
],
metadata: None,
// default_kind: 1,
// pow_difficulty: 0,
};
let client = NostrClient::new(config).await?;
// Send encrypted message
client
.send_message(
"Hello, this is an encrypted message!",
Some("recipient_pubkey"),
)
.await?;
// Publish public note (commented out - API not yet implemented)
// let event = client.create_text_note("Hello Nostr world!")?;
// client.publish_event_to_best_relays(event).await?;
// Monitor relay health (commented out - API not yet implemented)
// for relay in client.get_healthy_relays().await? {
// println!("Healthy relay: {}", relay);
// println!(
// "Health score: {}",
// client.get_relay_health_score(&relay).await?
// );
// }
println!("Nostr client example completed successfully!");
Ok(())
}