nostr_dart 0.3.0 copy "nostr_dart: ^0.3.0" to clipboard
nostr_dart: ^0.3.0 copied to clipboard

outdated

A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.

example/main.dart

import 'package:nostr_dart/nostr_dart.dart';

void main() async {
  // Generate a new private key
  final privateKey = generatePrivateKey();
  final publicKey = getPublicKey(privateKey);
  print('Private Key: $privateKey\nPublic Key: $publicKey\n');

  // The client API is provided by the Nostr class.
  final nostr = Nostr(privateKey: privateKey, powDifficulty: 16);

  // Connect to a Nostr relay. This is an asynchronous operation so
  // consider using the `await` keyword.
  const relayUrl = 'wss://relay.nostr.info';
  await nostr.addRelay(relayUrl);

  // Retrieve an event
  final subId = await nostr.subscribe({
    "ids": ["00002de2e06d9630b58df3bc4f10e27febbc089286b5498bbbcac9baef3dd45a"]
  });

  // Read received events
  for (Event event in nostr.events) {
    print('${event.content}\n');
  }

  // Publish a text note and confirm the operation was successful
  var result = await nostr.sendTextNote('Hello Nostr!');
  if (result.success) {
    print('winning!');
  }

  // Publish a relay recommendation
  await nostr.recommendServer('wss://nostr.onsats.org');

  // Update metadata
  await nostr.setMetaData(name: "my-name");

  // Publish a contact list
  final contacts = ContactList();
  final alice = Contact(
      publicKey:
          "253d92d92ab577f616797b3660f5b0d0f5a4ecd77a057891fea798c16b2abdce",
      url: "wss://alicerelay.com/",
      petname: "alice");
  contacts.add(alice);
  await nostr.sendContactList(contacts);

  // Publish an arbitrary event
  final event = Event(publicKey, 1, [], "A beautifully handcrafted event");
  await nostr.sendEvent(event);

  // Remove subscription and disconnect from the relay
  nostr.unsubscribe(subId);
  nostr.removeRelay(relayUrl);
}
1
likes
0
points
79
downloads

Publisher

unverified uploader

Weekly Downloads

A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bip340, clock, crypto, hex, string_validator, web_socket_channel

More

Packages that depend on nostr_dart