Quickstart

Rust

Create a client and connect to some relays.

    let my_keys: Keys = Keys::generate();

    let client = Client::new(&my_keys);
    let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));

    client.add_relay("wss://relay.damus.io").await?;
    client
        .add_relay_with_opts(
            "wss://relay.nostr.info",
            RelayOptions::new().proxy(proxy).flags(RelayServiceFlags::default().remove(RelayServiceFlags::WRITE)),
        )
        .await?;
    client
        .add_relay_with_opts(
            "ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion",
            RelayOptions::new().proxy(proxy),
        )
        .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: SubscriptionId = 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

TODO

JavaScript

TODO

Kotlin

TODO

Swift

TODO