sendEvent method

Event sendEvent(
  1. Event event
)

Publishes an arbitrary event.

Allows a custom Event to be composed and sent to connected relays.

Note that the transmission of the event to connected relays occurs asynchronously. nostr_dart maintains a message queue for each relay so that messages will be sent one at a time only after the previous message has acknowledged by the relay or a timeout occurs. This requires relays used to support NIP-15 and NIP-20.

The Event returned is the Nostr event that was published.

An ArgumentError is thrown if the private key hasn't been set.

Example:

final event = Event(
  "91cf9..4e5ca", 1, [], "A beautifully handcrafted event");
var event = nostr.sendEvent(event);

Implementation

Event sendEvent(Event event) {
  if (_privateKey.isEmpty) {
    throw StateError("Private key is missing. Message can't be signed.");
  }
  event.doProofOfWork(powDifficulty);
  event.sign(_privateKey);
  pool.send(["EVENT", event.toJson()]);
  return event;
}