dart_nostr 1.3.3 copy "dart_nostr: ^1.3.3" to clipboard
dart_nostr: ^1.3.3 copied to clipboard

This is a helper package that simplify and accelerate the use of Nostr protocal in Dart/Flutter environment

example/main.dart

import 'dart:async';

import 'package:dart_nostr/dart_nostr.dart';

Future<void> main() async {
  // This method will enable the logs of the library.
  Nostr.instance.enableLogs();

  // generates a key pair.
  final keyPair = Nostr.instance.keysService.generateKeyPair();

  // init relays
  await Nostr.instance.relaysService.init(
    relaysUrl: ["wss://relay.damus.io"],
  );

  final currentDateInMsAsString =
      DateTime.now().millisecondsSinceEpoch.toString();

  // create an event
  final event = NostrEvent.fromPartialData(
    kind: 1,
    content: "example content",
    keyPairs: keyPair,
    tags: [
      ["t", currentDateInMsAsString],
    ],
  );

  // send the event
  Nostr.instance.relaysService.sendEventToRelays(event);

  await Future.delayed(Duration(seconds: 5));

  // creating a request for listening to events.
  NostrRequest request = NostrRequest(
    filters: [
      NostrFilter(
        kinds: [1],
        t: [currentDateInMsAsString],
        authors: [keyPair.public],
      ),
    ],
  );

// listen to events
  final sub =
      Nostr.instance.relaysService.startEventsSubscription(request: request);

  sub.listen((event) {
    print(event);
  });
}
6
likes
0
pub points
68%
popularity

Publisher

verified publishergwhyyy.com

This is a helper package that simplify and accelerate the use of Nostr protocal in Dart/Flutter environment

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bip340, convert, crypto, equatable, http, meta

More

Packages that depend on dart_nostr