onNew

Sets up a listener for the event when a new mail is sent.

Usage

const receiver = '0x...';
const sender = '0x...';

// Listen to received mails
mail.onNew(null, receiver, (envelope) => {
  console.log(envelope);
});

// Listen to sent mails
mail.onNew(sender, null, (envelope) => {
  console.log(envelope);
});

// Listen to all mails
mail.onNew(null, null, (envelope) => {
  console.log(envelope);
});

Stop watching

// Listen to received mails
const stopWatching = mail.onNew(null, receiver, (envelope) => {
  console.log(envelope);
});

// ... Later, to stop watching for the events
stopWatching();

Returns

UnwatchFn

A function that can be invoked to stop watching for new event logs.

Parameters

sender

  • Type Address | null

The mail sender's address. If set to null, it listens for mails from any sender.

receiver

  • Type Address | null

The mail receiver's address. If set to null, it listens for mails to any receiver.

callback

  • Type (envelope: ReceivedEnvelope) => void

The callback function to be executed when a new mail event is detected. It receives a ReceivedEnvelope as its only argument.

Previous
downloadAttachment