Eventeum – Listen to the Ethereum event your way!

Tram Ho

In a few posts building the Backend for the Decentralized Application (ĐApp) we also mentioned that the event in Ethereum is unstable. So we need to build a mechanism that can listen, store and handle events more effectively.

Eventeum is a solution.

What is the eventeum

The eventeum is an Ethereum event listener , acting as a bridge between the smart contract event and the backend.

Whenever an event occurs, a message containing all the details of the event will be stored at the message bus (Kafka or RabbitMQ), then processed by backend services.

The eventeum is open source , developed by the kauri.io team.

Why Eventeum

If compared to listening directly and handling event directly in the backend, Eventeum has many outstanding points, such as:

  • Dynamically Configurable : The eventeum provides REST API to make subscribed / unsubscribed to any event very simple.
  • Highly Available : The Eventeum always ensures that all instances will subscribed to the same event collection with each smart contract.
  • Resillent : Although the node we connect to may die, the event subscription will continue once the node is alive again.
  • Fork Tollerance : The eventeum can be configured to wait for a period of time after a certain number of blocks have been confirmed . If a fork event occurs during that period, a message will be broadcast to the entire network, making it possible to handle the logic specific to this fork event.

Deploying Eventeum

Eventeum supports the following broadcast message methods:

  • Kafka
  • HTTP Post
  • RabbitMQ
  • Pulsar

With RabbitMQ we can configure the following fields:

  • rabbitmq.blockNotification (true or false)
  • rabbitmq.routingKey.contractEvents
  • rabbitmq.routingKey.blockEvents
  • rabbitmq.routingKey.transactionEvents

Prerequisites

  • Java8
  • Maven
  • Mongo
  • Kafka
  • Zookeeper
  • Ethereum Node
  • Docker

It may seem like a lot of hassle when a lot of things are installed, but we can simplify this installation by using Docker as follows:

  • clone repo of Eventeum about:

  • Move to the root directory

  • compile and test package

  • run docker

Ok so we have the Eventeum running on our machine. The eventeum will default to running at port 8060 .

Deploy smart contract

In this article we will use the Remix IDE to write and deploy contracts quickly.

The blockchain used is ganache, run by ganache-cli at port 8545. If you don’t have ganache-cli, you can install it using npm as follows:

and proceed to run the chain up:

Now we have a blockchain running at http://127.0.0.1:8545 .

Next, we will prepare a simple contract as follows:

On Remix, proceed with the compile contract, make sure that no errors occur:

Before deploying, remember to select the network as Web3 Provider and select the address http://127.0.0.1:8545 as the blockchain address we just ran above.

and proceed to Deploy:

So now we have the contract deployed to the blockchain.

Register Event

Next we will register the event with the Eventeum, so that whenever the event occurs it will capture that event, here is the CounterUpdated event we have defined in the contract.

  • URL: /api/rest/v1/event-filter
  • Method: POST

For simplicity, here we call with curl, replace the CONTRACT_ADDRESS segment with the contract address we deployed at Remix above:

If successful, we will see a message like this in the docker log mesages:

We will check if after registering with the Eventeum then when interacting with the contract, the event was fired by going to Remix and performing the following transaction:

On the docker logs of the eventeum, we get the following log:

means that our event listener has been successfully installed!

Eventeum has many other APIs, you can refer to here .

Subscribing Eventeum events in the NodeJs application

We will build a small application nodejs to be able to visualize how the Eventeum integration into the app is realistic.

The content of index.js very simple, listen to what you can log out. Here we use topic contract-events , this is a builtin of Eventeum, it will check all the topics that have been defined inside the Eventeum.

Run another transaction on Remix:

We will see that the nodejs log will look like this:

thus we have successfully integrated Eventume into a nodejs application.

Conclude

With small systems, the event log is not too much, we can use the plan to listen directly from the network and handle it as soon as we can listen.

However as our system grows, requires a lot of events and complex structures, then Eventum will be an effective choice.

Refer

Share the news now

Source : Viblo