![]() |
VOOZH | about |
dotnet add package Nostr.Client --version 2.1.0
NuGet\Install-Package Nostr.Client -Version 2.1.0
<PackageReference Include="Nostr.Client" Version="2.1.0" />
<PackageVersion Include="Nostr.Client" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="Nostr.Client" />Project file
paket add Nostr.Client --version 2.1.0
#r "nuget: Nostr.Client, 2.1.0"
#:package Nostr.Client@2.1.0
#addin nuget:?package=Nostr.Client&version=2.1.0Install as a Cake Addin
#tool nuget:?package=Nostr.Client&version=2.1.0Install as a Cake Tool
👁 .NET Core
👁 NuGet version
👁 NuGet downloads
This is a C# implementation of the Nostr protocol found here:
https://github.com/nostr-protocol/nips
Nostr protocol is based on websocket communication. This library keeps a reliable connection to get real-time data and fast execution of your commands.
Apache License 2.0
var url = new Uri("wss://relay.damus.io");
using var communicator = new NostrWebsocketCommunicator(url);
using var client = new NostrWebsocketClient(communicator, null);
client.Streams.EventStream.Subscribe(response =>
{
var ev = response.Event;
Log.Information("{kind}: {content}", ev?.Kind, ev?.Content)
if(ev is NostrMetadataEvent evm) {
Log.Information("Name: {name}, about: {about}", evm.Metadata?.Name, evm.Metadata?.About);
}
});
await communicator.Start();
var ev = new NostrEvent
{
Kind = NostrKind.ShortTextNote,
CreatedAt = DateTime.UtcNow,
Content = "Test message from C# client"
};
var key = NostrPrivateKey.FromBech32("nsec1xxx");
var signed = ev.Sign(key);
client.Send(new NostrEventRequest(signed));
var sender = NostrPrivateKey.FromBech32("nsec1l0a7m5dlg4h9wurhnmgsq5nv9cqyvdwsutk4yf3w4fzzaqw7n80ssdfzkg");
var receiver = NostrPublicKey.FromBech32("npub1dd668dyr9un9nzf9fjjkpdcqmge584c86gceu7j97nsp4lj2pscs0xk075");
var ev = new NostrEvent
{
CreatedAt = DateTime.UtcNow,
Content = $"Test private message from C# client"
};
var encrypted = ev.EncryptDirect(sender, receiver);
var signed = encrypted.Sign(sender);
client.Send(new NostrEventRequest(signed));
var relays = new[]
{
new NostrWebsocketCommunicator(new Uri("wss://relay.snort.social")),
new NostrWebsocketCommunicator(new Uri("wss://relay.damus.io")),
new NostrWebsocketCommunicator(new Uri("wss://nos.lol"))
};
var client = new NostrMultiWebsocketClient(NullLogger<NostrWebsocketClient>.Instance, relays);
client.Streams.EventStream.Subscribe(HandleEvent);
relays.ToList().ForEach(relay => relay.Start());
More usage examples:
window.nostr capability for web browserse and p tags in text eventsnostr: Protocol handler (web+nostr)Pull Requests are welcome!
A built-in reconnection invokes after 1 minute (default) of not receiving any messages from the server.
It is possible to configure that timeout via communicator.ReconnectTimeout.
Also, a stream ReconnectionHappened sends information about a type of reconnection.
However, if you are subscribed to low-rate channels, you will likely encounter that timeout - higher it to a few minutes or implement ping-pong interaction on your own every few seconds.
In the case of Nostr relay outage, there is a built-in functionality that slows down reconnection requests
(could be configured via client.ErrorReconnectTimeout, the default is 1 minute).
Beware that you need to resubscribe to channels after reconnection happens. You should subscribe to ReconnectionHappened stream and send subscription requests.
The library is prepared for replay testing. The dependency between Client and Communicator is via abstraction INostrCommunicator. There are two communicator implementations:
NostrWebsocketCommunicator - real-time communication with Nostr relay.NostrFileCommunicator - a simulated communication, raw data are loaded from files and streamed.Feel free to implement INostrCommunicator on your own, for example, load raw data from database, cache, etc.
Usage:
var communicator = new NostrFileCommunicator();
communicator.FileNames = new[]
{
"data/nostr-data.txt"
};
communicator.Delimiter = "\n";
var client = new NostrWebsocketClient(communicator);
client.Streams.EventStream.Subscribe(trade =>
{
// do something with an event
});
await communicator.Start();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 4 NuGet packages that depend on Nostr.Client:
| Package | Downloads |
|---|---|
|
PlangLibrary
Plang language core |
|
|
MarmotCs.Core
Marmot CS - C# secure group messaging with MLS (RFC 9420) + Nostr |
|
|
NostrServices.Client
Client wrapper for https://nostr.api.v0l.io |
|
|
MarmotMdk.Core
Marmot MDK - C# secure group messaging with MLS (RFC 9420) + Nostr |
Showing the top 1 popular GitHub repositories that depend on Nostr.Client:
| Repository | Stars |
|---|---|
|
v0l/void.cat
Free file hosting website
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 5,232 | 11/19/2025 |
| 2.0.0 | 7,900 | 11/16/2023 |
| 1.4.3 | 2,388 | 8/1/2023 |
| 1.4.2 | 743 | 6/25/2023 |
| 1.4.1 | 642 | 6/21/2023 |
| 1.4.0 | 1,510 | 4/28/2023 |
| 1.3.1 | 751 | 4/20/2023 |
| 1.3.0 | 706 | 4/19/2023 |
| 1.2.4 | 682 | 4/17/2023 |
| 1.2.3 | 725 | 4/4/2023 |
| 1.2.2 | 735 | 3/10/2023 |
| 1.2.1 | 726 | 3/7/2023 |
| 1.2.0 | 745 | 3/3/2023 |
| 1.1.2 | 724 | 2/23/2023 |
| 1.1.1 | 786 | 2/23/2023 |
| 1.1.0 | 730 | 2/23/2023 |
| 1.0.4 | 721 | 2/21/2023 |
| 1.0.3 | 777 | 2/18/2023 |
| 1.0.2 | 730 | 2/18/2023 |
| 1.0.1 | 768 | 2/18/2023 |
Enhancements