nostr_dart 0.3.0 nostr_dart: ^0.3.0 copied to clipboard
A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.
A Nostr client library written in Dart.
Features #
Use this library in your Dart/Flutter app to:
- Connect to Nostr relays.
- Publish
set_metadata
,text_note
,recommend_server
andcontact_list
events to connected relays. - Request events and subscribe to updates.
Supported Nostr Implementation Possibilities:
- NIP-01: Basic protocol flow description
- NIP-02: Contact List and Petnames
- NIP-13: Proof of Work
- NIP-15: End of Stored Events Notice
- NIP-20: Command Results
Getting started #
Add the following to your pubspec.yaml
:
dependencies:
nostr_dart: ^[version]
Usage #
Initialise nostr_dart
:
import 'package:nostr_dart/nostr_dart.dart'
final nostr = Nostr(privateKey: [private key], powDifficulty: [difficulty]);
Add a relay:
await nostr.addRelay([relay url]);
Retrieve events from connected relays and subscribe to updates:
final subId = await nostr.subscribe([filters], [subscription id])
Read retrieved events:
for (Event event in nostr.events) {
print('ID: ${event.id}. Content: ${event.content}');
}
Publish a text note:
final result = await nostr.sendTextNote([content], [tags]);
Publish metadata:
final result = await nostr.setMetaData(name: [name], about: [about], picture: [picture url]);
Publish server recommendation:
final result = await nostr.recommendServer([relay url]);
Publish a contact list:
final contacts = ContactList();
final contact = Contact(publicKey: [public key], url: [relay url], petname: [petname]);
contacts.add(contact);
final result = await nostr.sendContactList(contacts);
Remove an existing subscription:
nostr.unsubscribe([subscription id]);
Remove a connected relay:
nostr.removeRelay([relay url]);