Steem Catcher Client: Listening to the Blockchain

in #witness-category4 months ago

SteemCodeHeather.jpg

Hello friends. A few days ago I was thinking about how it would affect the development of applications on Steem from the client side if the client didn't have to worry about searching for the data; just listening to the network flow and filtering what they want.

I'm talking about working in real time. Let's say the blockchain "shouts out" announcing the transactions to anyone who is willing to listen. Maybe a bot to warn on Discord that a person has published a post or that someone is voting content or that they are performing certain transactions.

I have configured a server on the Internet that is constantly scanning the transactions in the blockchain, block by block, as they are generated. This server broadcasts messages to the network using the Sockets.io library protocol. These messages can be captured as events according to the different actions that occurred in the transaction.

List of actions that can be "caught":

 - post
 - comment
 - comment_options
 - delete_comment
 - vote

 - transfer
 - transfer_to_vesting
 
 - custom_json

 - claim_account
 - created_claimed_account
 - account_update
 - claim_reward_balance
 - delegate_vesting_shares

 - feed_publish

 - limit_order_create
 - limit_order_cancel

How does it work?

I've posted on Github some sample JavaScript code (and another Python example will be available soon) about how we can connect a Socket.io client and how we can capture activities on the Steem blockchain.

The first thing we need is to install the Socket.io client module

npm install socket.io-client

Then, in the code of our program, we must connect the socket to my server from where the transactions are broadcast:

const io = require('socket.io-client');
const ioSteem = io("http://steemcatcher.net");

To capture a type of action we must capture its associated event. The names of the events are the same that I have indicated in the previous list.

If we want to analyze the votes that are being made we can write:

ioSteem.on("vote", data => {
    ...
    code
    ...
});

The data object contains the information of the captured action in JSON format. For the example of a vote, the data content will be

voter: data.voter
author: data.author
permlink: data.permlink
weight: data.weight

We can do something like this:

ioSteem.on("vote", data => {
    if( data.voter == "@marcosdk" && data.author == yourSteemUserName ){
      console.log('The nice guy ' + data.voter + '  has voted my post ' + data.permlink + ' with the value of ' + data.weight);
    }
});

The program must be constantly listening so, in my example, I have configured a node.js + express server for this.

I don't know if this can really be useful. I thought it was a fun use case and I would like to see what utilities you can think of for this tool.

The code

You can clone de repository from Github:

https://github.com/3dkrender/SteemCatcher

Happy coding!

Please consider giving me a vote as Steem Witness or setting me up as your proxy, thank you.

image.png

Sort:  

Interesting to see what sort of uses could be made from this?

Desktop notification popup?

Recording entries in a contest?

Do you have any uses in mind?

Indeed! Those are possible applications for this tool. I'm going to try to create a tutorial to make a Discord Bot that uses this tool to warn of account postings in tracking 😃

Coin Marketplace

STEEM 0.20
TRX 0.03
JST 0.030
BTC 36868.36
ETH 1248.30
USDT 1.00
SBD 3.25