NostrO2

This crate is our first approach at building simple Rust tools for interacting with the Nostr ecosystem.

Features

Installation

Add nostro2 to your Cargo.toml dependencies:

toml [dependencies] nostro2 = "0.1.3"

Example

Using this library is straightforward. Connect to a relay, send a subscription event, and await the received messages.

Rust and serde allow for performant parsing of the notes into objects, which can then be pattern matched with ease.

```rust let nostr_relay = NostrRelay::new("wss://nostr.bongbong.com").await.unwrap(); let filter: Value = json!({ "authors": vec!(pubkey), "kinds": [1] });

nostr_relay.subscribe(filter).await.unwrap();

let mut found_note: Option = None;

while let Some(result) = nostrrelay.readnotes().await { match result { Ok(note) => { info!("Nota: {}", note.tostring()); if let Ok((notice, id, signednote)) = fromstr::<(String, String, SignedNote)>(&note) { foundnote = Some(signednote); break; } } _ => { nostrrelay.close().await.expect("Error"); return Err("Error".to_string()); } } } ```