diff --git a/crates/nostr-sdk/Cargo.toml b/crates/nostr-sdk/Cargo.toml index c875802a6..3f5229388 100644 --- a/crates/nostr-sdk/Cargo.toml +++ b/crates/nostr-sdk/Cargo.toml @@ -45,12 +45,16 @@ tokio = { workspace = true, features = ["rt", "macros", "sync"] } [dev-dependencies] tracing-subscriber = { workspace = true, features = ["env-filter"] } +[[example]] +name = "client-with-opts" +required-features = ["all-nips"] + [[example]] name = "client" required-features = ["all-nips"] [[example]] -name = "client-with-opts" +name = "get-events-of" required-features = ["all-nips"] [[example]] diff --git a/crates/nostr-sdk/examples/get-events-of.rs b/crates/nostr-sdk/examples/get-events-of.rs new file mode 100644 index 000000000..6fcb614d3 --- /dev/null +++ b/crates/nostr-sdk/examples/get-events-of.rs @@ -0,0 +1,33 @@ +// Copyright (c) 2022-2023 Yuki Kishimoto +// Distributed under the MIT software license + +use std::time::Duration; + +use nostr_sdk::prelude::*; + +const BECH32_SK: &str = "nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85"; + +#[tokio::main] +async fn main() -> Result<()> { + tracing_subscriber::fmt::init(); + + let secret_key = SecretKey::from_bech32(BECH32_SK)?; + let my_keys = Keys::new(secret_key); + + let client = Client::new(&my_keys); + client.add_relay("wss://relay.damus.io", None).await?; + client.add_relay("wss://nostr.wine", None).await?; + client.add_relay("wss://relay.nostr.info", None).await?; + + client.connect().await; + + let filter = Filter::new() + .author(my_keys.public_key().to_string()) + .kind(Kind::Metadata); + let events = client + .get_events_of(vec![filter], Some(Duration::from_secs(10))) + .await; + println!("{events:#?}"); + + Ok(()) +}