## Proof of Concept: Polkadot - notify me
#### *(or Substrate-based Chains Notification System)*
### *TL;DR:* A dead-simple, yet highly effective notification system for Polkadot and its parachains (or, any substrate-based chain).
---
The idea was introduced by @kianenigma and his repo [polkadot-basic-notification](https://github.com/kianenigma/polkadot-basic-notification) which is describing a functional notification system, that anyone can run locally and based on a [json coniguration](https://github.com/kianenigma/polkadot-basic-notification/blob/master/examples/config-dev-all.json) provided by the runner, this app can send notifications to various providers (e.g. log console, telegram, email, element/matrix);
My thinking was, that this is a great idea, and can be extremelly useful for the ecosystem, so I added it under my wing (with Kian's blessings) as a pet-project in order to bring it to a (let's call it) "more useful and better" state and to create a Proof of concept;

## The vision
The importance this project, to me,is three-fold, separated in 2 categories (User and dApp/Network related):
a) (`User category`) A way for the user to understand that his account is "active" and things are happening behind the scenes, when in exchanging, staking, and/or being in a pool; User can be informed by rewards or transfers that occur during him/her being disconnected;
b) (`User category`) App can act as a call-to-action for the user of the subscribed account(s); When informed through the means, one can react by returning to his wallet and interact based on the notification received (retrieve rewards, stake more etc etc.);
c) (`Network/dApp category`) App can act as a "network alert" notification system - thus a Network can be alerted (through an account) for network malfunctions or alerts that needs immediate attention (a good example is to listen to `force fix` action on a chain etc.);
The fully flexed vision as have been thought so far is for a user to be able by using 1 of his accounts (subscribed account) to choose through a simple UI:
a) which accounts wants to monitor;
b) which chains wants to monitor for the aforementioned accounts;
c) which methods (event, transactions) wants to monitor for the aforementioned accounts per chain;
d) which reporters wants to use for receiving notifications;
## Current state
At the moment, the service/app has several bugs that need to be resolved and there are missing features but I preferred since this PoC seem to work smoothly and nicely to share with the rest of you, for gathering feedback, understanding the needs more and allowing more to reach out and participate in the testing (adding their accounts) etc.
After spending few hours on converting Kian's code to an API, building a [UI around it](http://polkadot-notify.me) etc etc the outcome of the current state is a functional PoC that one can connect a wallet, and add (subscribe) or remote (unsubscribe) his accounts from the service, see the subscriptions, start/stop the subscriptions and edit them;
**http://polkadot-notify.me** : The UI for now is dead-simple; It only contains a landing page where a user can connect extensions and accounts:

Once user chooses the account that wants to be subscribed with then moves to a "settings" page where can choose which accounts wants to monitor, which chains wants to monitor for the aforementioned accounts, which methods (event, transactions) wants to monitor for the aforementioned accounts per chain, which reporters wants to use for receiving notifications:

The service is running on a simple droplet in digitalOcean as a PoC, and due to the limited resources (1 regular Intel vCPU, 2 GB Memory and 2 TB of transfer), the signups and edits have been disabled; It is currently monitoring approximately 6-7 accounts of users that I asked and wanted to participate in this early stage, in the following networks, Polkadot, Kusama, Westend, Rococo, Karura, Khala. Based on very primitive and simple counting in the past few days it has sent more than 100 notifications to those accounts;
Below can be found the statistics of the service running in the dropplet for the past 7 days:


Its obvious that the service fromthe 9th of May, has many bugs resolved and becoming more effecient while code is developed (still it is not there :) );
Below there are some sample notifications as appear in email, telegram and element/matrix providers.
Email:

Element/Matrix:

Telegram:

## Some Issues under consideration
#### Costs of infrastructure:
As mentioned above the service is running under a simple dropplet of DigitalOcean. The usage of PolkadotJS API for monitoring the chains has proven that it has extra memory needs and abnormal closures of the API - but when integrated a light-client it looked like these issues were resolved; It is still not production-ready concerning Smoldot integration for the well known clients (Polkadot, Kusama, Westend, Rococo) - but its almost there, and this will for sure reduce theses costs;
#### API usage:
As mentioned PolkadotJS Api is used which seems to face some issues with abnormal closures - maybe to the long-open websocket. As per logs, it shuts down approx. every 18-24 hours; I need to dig deeper for resolving this, and I would like also to integrate CAPI for checking the performance; DigitalOcean resumes automatically the service when ws closes abnormally, and an implementation of an sqlite3 filebased db "keeps" the accounts and the settings; From that sqlite the app resumes the notification service for all these accounts;
#### Security and abusing the service:
There is a lot of thought I have put on this, and yet do not have a declarative answer; Concerning security there are plenty of actions that can be taken in order to protect user's data and make this service decentralized, since as of now it is not;
Concerning abusing the service: see below on the "fees" that this service could cost in order to address the "overusing" of the service from accounts;
An extra idea - in order to cover the infra expenses (and disallowing people "just using" the service - thus increasing the costs) - is to add a minor fee for the subscribed account. This fee can be as high as 0.01 DOT (0.05 EUR per account/per watching addresses/per day) and adjust based on DOT price in order to stay in a low level (e.g. if DOT moves from 5 EUR -> 50 EUR on a bull market, the fee should decrease);
## Where it could go from here:
The idea I have for the project is to be under Parity, as a "helper" project for the "Onboarding the world" team;
It can help users understand how to connect their accounts, and to see the "interactions" that these accounts have with the chain through notifications; By making the notifications more user friendly and introducing tips, and links for the users we can verify this app to be a constant "integration" between users and networkds, even when users are not logged in to their favourite apps; E.g. a "stake rewards notification" can bring the user back to the dashboard in order to interact with it; a "new vote begun" for Governance can do the same etc etc;
It can help teams/networks to identify issues on the chain instantly and act upon specific notifications;
In the future, more providers can be integrated, in order to deliver notifications through more platforms/channels than just the ones mentioned here such as e.g. Signal, Whatsapp, normal SMS, FAX(?) etc etc
## Conclusion
The idea seems useful and exists already for notification needs, a (very expensive) positevly-voted [**treasury proposal by a team called NotiFi**](https://polkadot.polkassembly.io/post/1767);
I believe the `polkadot-notify.me` is a product that can be maintened under Parity and provide a layer of connection between the network and the world;
With this post I want to reach out on opinions, suggestions, interest, feedback, testing participation etc etc;
Thank you.