React Native theorytheory 0/50 · 0%
Native APIs · medium

28. Push notifications

Alerting users to on-chain events.

Push notifications (via Expo Notifications or Firebase Cloud Messaging) can alert a user when a pending transaction confirms, or when a price alert triggers, even while the app is backgrounded.

import * as Notifications from "expo-notifications";

async function notifyTxConfirmed(hash: string) {
  await Notifications.scheduleNotificationAsync({
    content: { title: "Transaction confirmed", body: `Tx ${hash.slice(0, 10)}… is confirmed` },
    trigger: null,
  });
}

Requesting notification permission should be done contextually (right before the feature that needs it, e.g. "enable alerts for your pending swap") rather than immediately on app launch, which tends to get denied.

Check your understanding

  1. 1. What can trigger a push notification in a wallet app?

  2. 2. When is it best to request notification permission?

  3. 3. Which library is commonly used for notifications in Expo apps?