40 releases (22 breaking)

0.25.0 Nov 1, 2023
0.23.0 Aug 17, 2023
0.22.0 May 18, 2023
0.20.1 Mar 25, 2023
0.5.1 Nov 14, 2022

#60 in FFI

Download history 303/week @ 2023-07-31 421/week @ 2023-08-07 499/week @ 2023-08-14 315/week @ 2023-08-21 796/week @ 2023-08-28 602/week @ 2023-09-04 565/week @ 2023-09-11 539/week @ 2023-09-18 447/week @ 2023-09-25 464/week @ 2023-10-02 510/week @ 2023-10-09 357/week @ 2023-10-16 604/week @ 2023-10-23 478/week @ 2023-10-30 679/week @ 2023-11-06 425/week @ 2023-11-13

2,234 downloads per month
Used in 12 crates (11 directly)

MIT license

15K SLoC

Nostr SDK

crates.io crates.io - Downloads Documentation Rustc Version 1.64.0+ CI MIT Lines of code


A high-level, Nostr client library written in Rust.

If you're writing a typical Nostr client or bot, this is likely the crate you need.

However, the crate is designed in a modular way and depends on several other lower-level crates. If you're attempting something more custom, you might be interested in these:

Getting started

nostr-sdk = "0.25"
tokio = { version = "1", features = ["full"] }
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use nostr_sdk::prelude::*;

async fn main() -> Result<()> {
    // Generate new keys
    let my_keys: Keys = Keys::generate();
    // or use your already existing
    // From HEX or Bech32
    // let my_keys = Keys::from_sk_str("hex-or-bech32-secret-key")?;

    // Show bech32 public key
    let bech32_pubkey: String = my_keys.public_key().to_bech32()?;
    println!("Bech32 PubKey: {}", bech32_pubkey);

    // Create new client
    let client = Client::new(&my_keys);

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

    // Add relays
    client.add_relay("wss://relay.damus.io", None).await?;
    client.add_relay("wss://relay.nostr.info", proxy).await?;

    // Connect to relays

    let metadata = Metadata::new()
        .display_name("My Username")
        .custom_field("custom_field", "my value");

    // Update metadata

    // Publish a text note
    client.publish_text_note("My first text note from Nostr SDK!", &[]).await?;

    // Create a POW text note
    let event: Event = EventBuilder::new_text_note("POW text note from nostr-sdk", &[]).to_pow_event(&my_keys, 20)?;

    // Send custom event
    let event_id = EventId::from_bech32("note1z3lwphdc7gdf6n0y4vaaa0x7ck778kg638lk0nqv2yd343qda78sf69t6r")?;
    let public_key = XOnlyPublicKey::from_bech32("npub14rnkcwkw0q5lnmjye7ffxvy7yxscyjl3u4mrr5qxsks76zctmz3qvuftjz")?;
    let event: Event = EventBuilder::new_reaction(event_id, public_key, "🧡").to_event(&my_keys)?;

    // Send custom event to all relays
    // client.send_event(event).await?;

    // Send custom event to a specific previously added relay
    client.send_event_to("wss://relay.damus.io", event).await?;


More examples can be found in the examples/ directory.


This crate supports the wasm32 targets.

An example can be found at nostr-sdk-wasm-example repo.

On macOS you need to install llvm:

brew install llvm
LLVM_PATH=$(brew --prefix llvm)
AR="${LLVM_PATH}/bin/llvm-ar" CC="${LLVM_PATH}/bin/clang" cargo build --target wasm32-unknown-unknown

NOTE: Currently nip03 feature not support WASM.

Crate Feature Flags

The following crate feature flags are available:

Feature Default Description
blocking No Needed to use NIP-05 and NIP-11 features in not async/await context
all-nips Yes Enable all NIPs
nip03 No Enable NIP-03: OpenTimestamps Attestations for Events
nip04 Yes Enable NIP-04: Encrypted Direct Message
nip05 Yes Enable NIP-05: Mapping Nostr keys to DNS-based internet identifiers
nip06 Yes Enable NIP-06: Basic key derivation from mnemonic seed phrase
nip11 Yes Enable NIP-11: Relay Information Document
nip44 No Enable NIP-44: Encrypted Payloads (Versioned) - EXPERIMENTAL
nip46 Yes Enable NIP-46: Nostr Connect
nip47 Yes Enable NIP-47: Nostr Wallet Connect

Supported NIPs

Look at https://github.com/rust-nostr/nostr/tree/master/crates/nostr#supported-nips


This library is in an ALPHA state, things that are implemented generally work but the API will change in breaking ways.


This project is distributed under the MIT software license - see the LICENSE file for details


⚡ Tips: https://getalby.com/p/yuki

⚡ Lightning Address: yuki@getalby.com


~405K SLoC