Ethereum Cloud Messaging Network

Decentralized network for sending browser push notification to user's Ethereum addresses

Subscribe to Notifications from Ethereum

Currently only on ROPSTEN

Upon subscription


For Developers

You can start sending push notifications by calling the send notification function on the ECM contract

  // using ethers.js : 
  const server = await this.contract.getUserRegistrationServer(user);
  const price = await this.contract.getServerPrice(server);
  this.contract.connect(this.signer).sendNotification(user, title, data, image, { value: price });        
            

Contract Address :

  0x2F04837B299d8eD4cd8d6bBa69F48EdFEc401daD

Contract ABI :

  [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"server","type":"address"},{"indexed":false,"internalType":"string","name":"encryptedPushToken","type":"string"},{"indexed":false,"internalType":"string","name":"title","type":"string"},{"indexed":false,"internalType":"string","name":"data","type":"string"},{"indexed":false,"internalType":"string","name":"image","type":"string"}],"name":"NewNotification","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"server","type":"address"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"}],"name":"NewServer","type":"event"},{"inputs":[{"internalType":"address","name":"server","type":"address"}],"name":"getServerPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"server","type":"address"}],"name":"getServerPublicKey","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"server","type":"address"}],"name":"getServerVapidKey","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserRegistrationServer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isUserRegistered","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"publicKey","type":"string"},{"internalType":"string","name":"vapidKey","type":"string"}],"name":"registerServer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"server","type":"address"},{"internalType":"string","name":"encryptedPushToken","type":"string"},{"internalType":"string","name":"metadata","type":"string"}],"name":"registerUser","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"string","name":"title","type":"string"},{"internalType":"string","name":"data","type":"string"},{"internalType":"string","name":"image","type":"string"}],"name":"sendNotification","outputs":[],"stateMutability":"payable","type":"function"}]
            

For Supporters

ECM network works better when more developers integrate ECM on their websites. By adding ECM to your website, you are connecting the service worker on your website to the ECM network. Other developers can pay to notify users through your website's service worker.

To support ECM :

1. Add the library to your website

  <script src="https://madhavanmalolan.github.io/ecm.js/ecm.js"></script>
  <script>
  async function register(){
    if(!window.ethereum){
        alert("You must install metamask to connect to ECM");
        window.location.href = "https://metamask.io";
    }
    await window.ethereum.enable();
    const ecm = new ECM();
    ecm.register("0x2F04837B299d8eD4cd8d6bBa69F48EdFEc401daD", true);  
  }
  async function init(){
    const ecm = await new ECM();
    if(await ecm.isRegistered()){
        document.getElementById('ecm_connect_button').setAttribute("src", "https://madhavanmalolan.github.io/ecm.js/ecm_connected.png");
    }
  }
  init();
  </script>
  <a href="https://madhavanmalolan.github.io/ecm.js"><img src="https://madhavanmalolan.github.io/ecm.js/ecm_notconnected.png" id="ecm_connect_button" style="position: fixed; height: 64; bottom:12; left: 12;"/></a>

            

2. Create a service worked

A service worked called sw.js in the root directory of your project such that is is accessible from /sw.js

  // sw.js
  self.addEventListener('push', function(e) {
    var options = {
      body: e.data.json().data,
    };
    e.waitUntil(
      self.registration.showNotification(`ECM: ${e.data.json().title}`, options)
    );
  });            
            

Become a service provider

ECM service providers can earn by being a relayer of notifications

1. Git Clone

  git clone https://github.com/madhavanmalolan/ecm.git
        

2. Install

  cd ecm && npm install 

3. Generate rsa keys

  $ openssl genrsa -out id_rsa 8192
  $ openssl rsa -pubout -in id_rsa -out id_rsa.pub
        

4. Generate VAPID keys

  $ node vapid_keys.js 

5. Populate .env

    RPC_ENDPOINT=wss://ropsten.infura.io/ws/v3/YOUR_INFURA_TOKEN
    CONTRACT_ADDRESS=0x2F04837B299d8eD4cd8d6bBa69F48EdFEc401daD
    VAPID_PUBLIC_KEY= ENTER VAPID PUBLIC KEY HERE
    VAPID_PRIVATE_KEY=ENTER VAPID PRIVATE KEY HERE
    ETH_ADDRESS= YOUR ETHEREUM ADDRESS
    ETH_PRIVATEKEY= YOUR ETHEREUM PRIVATE KEY
        

6. Start and keep service running

You must run the server continuously

  screen -d -m node index.js  

7. Register your service provider

Follow this link to register
Set payable value to be the number of wei a developer should pay to send a notification to a user registered to your server.

8. Ask Supporters to use your eth address in the ECM instance on their websites

When notifications are sent to the users on your server, you earn ETH

  const ecm = new ECM();
  ecm.register("YOUR ADDRESS HERE", true);