Alerts Quick Start
An end-to-end guide on setting up notifications for your dapp.
Last updated
An end-to-end guide on setting up notifications for your dapp.
Last updated
This section provides an end-to-end quick start guide to get set up sending notifications to your users from your dApp. We get you set up for production use by walking through the following steps:
Create and configure your dApp keypair, which you use to send notifications.
Add our notifications component to your front end, for users to register and receive the notifications from you.
Send dApp notifications from your backend.
Try a live example of this notification bell at https://alerts-example.dialect.to.
Dialect's protocol enables communication between wallets, and dApp notifications are no exception. To send notifications to user wallets, dApps should first create a keypair for messaging.
Create keypairs for your dapp and for a test user. For your test user, you may also use existing test keypairs you have, as this keypair will eventually get added to a chrome extension wallet such as Phantom for testing our front end component libraries.
We recommend using the Solana CLI to create a new keypair.
DO NOT share your dApp private key with anyone, not even Dialect. We never store your private key anywhere in our systems, and will never ask for it. It is for you and your use alone.
You'll need the public and private keys of this keypair in the following sections.
In the following sections you'll execute code from Dialect's typescript SDK. First set up your preferred node and typescript environment. Then install and import Dialect SDK dependencies, and create a Dialect SDK instance.
In this section, you'll install Dialect and Solana dependencies for both the frontend and backend requirements. You'll then use the backend dependencies to create a Dialect SDK instance, which you will use to register your keypair as a dApp in our system.
The documentation assumes that you already have @solana/web3.js
installed and configured on your backend app.
In order to start adding messaging functionality to your web dApp, we need to install a few essential packages first.
npm:
yarn:
Set DIALECT_SDK_CREDENTIALS
environment variable to your dApp's Solana keypair, which was generated above.
Register your dapp keypair, so user keypairs can then register to and then receive notifications from you.
Head to https://dashboard.dialect.to, connect your dapps’ wallet and register your dApp name and description to start sending notifications.
You'll use this same SDK setup and configuration in your backend to send dApp notifications, as described below in Send notifications from your backend.
But first, let's add the notification bell to your react app, where you'll be able to subscribe for notifications and then receive them as a test user.
Dialect's @dialectlabs/react-ui
library provides out-of-the-box react components for embedding a notification bell in your react app, from which your users can fully manage their notifications experience with you. It is a pre-built, themeable, self-sufficient, and opinionated set of UI components for your users that abstracts away a large amount of the notifications logic. Specifically, it handles:
Registration for in-app, email, and Telegram notifications, including full email and Telegram verification flows.
Registration for any number of notification types you choose to create. This could be price alerts, liquidation warnings, NFT bid events, or anything else you can dream up.
In-app feed of notifications, including a badge on the notification bell to let your users know when they have unread notifications.
We strongly recommend you use our react components to manage your client experience for your users in your dapp. These components are fully stylable to your brand, and will reduce your implementation time by 80% or more.
All you need to do as a developer is add this component to your react app, and the rest comes out of the box. Let's go through adding this component to your app.
The documentation assumes that you already have the Solana wallet adapter installed and configured in your app. If you don't, follow this wallet adapter guide to install it.
In order to start adding messaging functionality to your web dApp, we need to install a few essential packages first.
npm:
yarn:
You are now ready to add the Dialect notification bell react component to your app. To do this, let's first create a separate component in your project and call it DialectNotificationComponent
. It should contain the code below:
Import styles from the Dialect UI library;
ConfiguresDialectSolanaSdk
which integrates with the wallet adapter;
Adds a notifications button;
Set DAPP_ADDRESS
variable to the public key generated in previous section;
Add this file to your project:
Now import this file into your main navbar component, as described in the next section.
Once you've configured your project with Dialect context providers as described in the previous section, you can simply drop in the Dialect notifications react component:
You're all set! Run your app now and use the notification bell to register for notifications for whichever test user wallet you'd like.
You will begin sending notifications to that test user in the next section.
To see a complete working example of our notifications bell, check out the example nextjs app in our react component library. You can run this example like you would any nextjs application, as described from that library.
Now that you have a notification bell and modal in your react app, let's use the dApp keypair we created above to begin sending notifications to users.
If you haven't already, make sure you've registered your dApp keypair (see Register your dapp).
And then create a Dialect SDK instance (see Create a Dialect SDK instance).
With your SDK instance, you can now run the following code to send a notification to all subscribed users.
If you've registered to receive notifications from your app, this notification should now appear in your notification modal.
This concludes the quick start guide. To do more advanced things like
sending notifications to specific wallets, or sets of wallets,
setting up notification types, or
sending notifications for specific notification types,
see the Notifications section for more info.