Broadcast Ethereum Events with Web3.js and PubNub by@adam.bavosa

Broadcast Ethereum Events with Web3.js and PubNub

Adam Bavosa HackerNoon profile picture

Adam Bavosa

In this post, we’ll show you how to harness the power of PubNub to amplify Ethereum smart contract events. Using our global, realtime network APIs, we’ll intelligently update the crowd watching your decentralized application.

What is Ethereum?

Ethereum is a decentralized blockchain network for running smart contracts. Let’s say you’ve created your DApp masterpiece, but you need a way to signal the execution of events to your constituency. An example of this would be a network of investors that are awaiting the opening of your Cryptotoken crowdsale. It’s time to use the PubNub megaphone to tell everyone that your crowdsale has opened, in realtime.


Web3.js is the JavaScript framework for interfacing with blockchain smart contracts. Whether you have a Node.js app, or a web browser front end, web3.js has 2 core purposes:

  • Trigger the execution of smart contract functions
  • Listen to events (like solidity events) that are signaled when a contract executes

The Crowdsale Has Opened!

Using the Crowdsalable Ethereum Token code we can write a Node.js app to listen for the Ethereum events and update all of our fans using PubNub.

PubNub is a realtime, global, data delivery network. We can make sure that all of our crowdsale investors, who may be staring at a purchase webpage while holding their breath, see that the sale has opened in an instant. PubNub can be used to keep a massive load of users in-sync, send realtime updates, and also perform data enrichment.

Supercharge Your Smart Contract Events

An app that is listening to Ethereum events, that is also connected to PubNub, can trigger push notifications, send text messages, send emails, and much more. Using Mobile Push, or PubNub Functions, tremendous capability is added to mere Ethereum events.

The Open Growth SDK uses PubNub Functions to collect user data with Clearbit, classify a customer’s use case with a machine learning API, and then submit an enriched alert. All of this functionality is triggered by one PubNub message. In this similar use case, PubNub can make your smart contract events powerful.


Here is the Node.js script that will commit the publish to PubNub’s network, which guarantees delivery in under a quarter of a second to your millions of patient investors.

You can check out the full GitHub Repo for this project.

In order to get this example running, you need to input the path of the JSON file for your smart contract build in line 4. Next paste in your PubNub API keys, and finally your contract’s address toward the bottom of the file. This code can be used in conjunction with the Crowdsalabe Token project mentioned earlier.

This connector opens the doors for PubNub Functions and Mobile Push Notifications to ensure that our constituency gets a text, email, push notification, and we can post to a Twitter account, all in an automated fashion.

Originally published at


Signup or Login to Join the Discussion


Related Stories