Usage
In this section, we showcase the aspects of using the Notify API. We’ll guide you through the initial steps of initializing the Notify client and logging in a blockchain account. You’ll also learn how to manage your subscriptions and messages. Additionally, we cover the process of setting up and displaying push notifications on your preferred platform. To ensure a good user experience, we include best practices for spam protection, helping you to enable the users to maintain control over the notifications wallet receives.
Content
Links to sections on this page. Some sections are platform specific and are only visible when the platform is selected. To view a summary of useful platform specific topics, check out Extra (Platform Specific) under this section.
- Initialization: Creating a new Notify Client instance and initializing it with a projectId from Cloud.
- Account login: A SIWE message must be signed by the user in order to authorize the client to use Notify API
- Subscribing to a new dapp: Opt-in to receive notifications from dapp
- Fetching active subscriptions: Get active subscriptions
- Fetching subscription’s notification: Get notifications of a subscription
- Fetching available notification types: Get latest notification types
- Updating subscriptions notification settings: Change allowed notification types sent by dapp
- Unsubscribe from a dapp: Opt-out from receiving notifications from a dapp
- Account logout: To stop receiving notifications to this client, accounts can logout of using Notify API
- Push Notification Setup: Configuring app in order to decrypt notifications
Initialization
Initialize the SDK clients
Add listeners for relevant events
Account login
In order to register account in Notify API to be able to subscribe to any dapp to start receiving notifications, account needs to sign SIWE message to prove ownership. Developers can check if an account is registered by calling isRegistered()
function. If the account is not registered, developers should call prepareRegistration()
and then register()
function to register the account.
This is a one-time action per account. It does not need to be repeated after initial registration of the new account.
Registering as a wallet
Subscribing to a new dapp
To begin receiving notifications from a dapp, users must opt-in by subscribing. This subscription process grants permission for the dapp to send notifications to the user. These notifications can serve a variety of purposes, such as providing updates on the user’s blockchain account activities or informing them about ongoing campaigns within the dapp. Upon initial subscription, clients will be automatically enrolled to receive all types of notifications as defined by the dapp at that moment. Users have the flexibility to modify their notification settings later, allowing them to tailor the types of alerts they receive according to their preferences.
To identify dapps that can be subscribed to via Notify, we can query the following Explorer API endpoint:
https://explorer-api.walletconnect.com/v3/dapps?projectId=YOUR_PROJECT_ID&is_notify_enabled=true
Fetching active subscriptions
To fetch the current list of subscriptions an account has, call getActiveSubscriptions()
.
Fetching subscription’s notifications
To fetch subscription’s notifications by calling getNotificationHistory()
.
Fetching available notification types
Developers can fetch latest notification types specified by dapp by calling getNotificationTypes()
function.
You can use the scope
object of the subscription to get the available notification types.
Updating subscriptions notification settings
Users can alter their notification settings to filter out unwanted alerts from a dapp. During this process, they review and select the types of notifications they wish to receive, based on the latest options provided by the dapp. Available notification types fetching is shown in the next section.
Unsubscribe from a dapp
To opt-out of receiving notifications from a dap, a user can decide to unsubscribe from dapp.
Account logout
If an account is removed from the client or a user no longer wants to receive notifications for this account, you can logout the account from Notify API by calling unregister()
. This will remove all subscriptions and messages for this account from the client’s storage.
Fetch notification history (Pagination)
There might be different approaches to implement pagination in your app depending on your needs. You can see the following example implemented with FlatList
which introduces infinite scroll functionality with a basic example:
Please make sure you have better handling of the notify client instance which handles worst cases by checking initialization status, account status, for production ready apps.
Push Notification Setup
Install @react-native-firebase/app
, @react-native-firebase/messaging
and @notifee/react-native
to handle Push Notifications.
Please refer to the respective package documentation to configure them properly.
Update your index.js
file to include the following logic.
Was this page helpful?