We Created an Event Notification System for NEO NeoLogin Follow Mar 6 · 3 min read

At Neologin, we care a lot about Neo and we believe in its community. Recently, we ran into a problem while building some cool stuff on top of Neo: for (off-chain) applications to be aware of events happening on Neo, developers currently have to run full nodes. This is a pretty big hurdle for some, so we set out to solve this. As such, we have built an event-notification system for Neo, which we will host and maintain for the community to use.

The event notification system

Our solution is to run nodes ourselves and to allow others to easily plug into our system to get notifications of on-chain events that are relevant for them.

In other words, we built a (free!) publish-subscribe service for Neo that allows anyone to listen for events happening on the blockchain and act on them.

It works by capturing all messages sent through the p2p-network that connects all of NEO’s nodes.

The service is based in web-sockets and can be used by just connecting to the following endpoints:

# Events triggered in all smart contract executions

wss://pubsub.main.neologin.io/event # Events triggered by a specific contract

wss://pubsub.main.neologin.io/event?contract=0xfb84b...bf43 # New blocks that have been included into the blockchain

wss://pubsub.main.neologin.io/block # Transactions that were just broadcasted on the network (still not confirmed!)

wss://pubsub.main.neologin.io/mempool/tx

Using Javascript, you can connect to these endpoints with the following code:

const ws = new WebSocket('wss://pubsub.main.neologin.io/event')

ws.onmessage = (event) => {

console.log(event.data);

}

If you wish to get events from the testnet instead of the mainnet just replace the main prefix with test , eg: pubsub.test.neologin.io .

Scalability

We’ve designed the system to handle high loads and to be able to scale horizontally. This is possible thanks to an architecture based around a singleton instance of a NEO node that gets all the data which is then relayed to a scalable amount of dynos hosted on heroku which maintain the websockets connections with all the clients and push the data to them. Thus we can dynamically scale the amount of dynos on heroku to meet demand.

Contributions

In building this event notification system for Neo, we have further:

Forked neo-pub-sub, updated it to work with the current versions of neo nodes (previously it would break because of changes made to neo nodes), extended it to relay events and more. See PR and PR

Deployed two public neo-pub-sub servers for everyone to use. These servers are on heroku and will auto-scale to meet demand.

Added 2 new full nodes (mainnet & testnet) to the neo network.

Wrote a guide on setting up a neo node with a reverse proxy and another one on how to install the NeoPubSub plugin

Improved monitor.cityofzion.io by adding support for websockets protocols, fixing it’s dependecies and establishing an automated build system for it. See PR.

Improved the NeoPubSub plugin slightly with several PRs

You can find the full description of the event notification system, including example events, here. The full system can be found at our Github.

We hope this is helpful for all of you building on Neo!