Quickstart
Rust
Create a client and connect to some relays.
let my_keys: Keys = Keys::generate();
let client = Client::new(&my_keys);
client.add_relay("wss://relay.damus.io").await?;
client.add_read_relay("wss://relay.nostr.info").await?;
client.connect().await;
Add metadata for the keys in the existing client.
let metadata = Metadata::new()
.name("username")
.display_name("My Username")
.about("Description")
.picture(Url::parse("https://example.com/avatar.png")?)
.banner(Url::parse("https://example.com/banner.png")?)
.nip05("username@example.com")
.lud16("yuki@getalby.com")
.custom_field("custom_field", "my value");
client.set_metadata(&metadata).await?;
Create a filter and notify the relays of the subscription.
let filter = Filter::new().kind(Kind::Metadata);
let sub_id = client.subscribe(vec![filter], None).await?;
For more supported filters, view the documentation.
Listen for notifications from the relays based on the subscribed filters and process them some way.
let mut notifications = client.notifications();
while let Ok(notification) = notifications.recv().await {
if let RelayPoolNotification::Event {
subscription_id,
event,
..
} = notification
{
if subscription_id == *sub_id && event.kind == Kind::Metadata {
// handle the event
break; // Exit
}
}
}
Python
Docs aren't ready yet, please check the examples at https://github.com/rust-nostr/nostr/tree/master/bindings/nostr-sdk-ffi/bindings-python/examples.
JavaScript
Docs aren't ready yet, please check the examples at https://github.com/rust-nostr/nostr/tree/master/bindings/nostr-sdk-js/examples.
Kotlin
TODO
Swift
TODO