Domain Steem with JavaScript: Lesson #3 - Hearing the blockchain

Hello everyone! Today I am here to participate in the Domain Steem with JavaScript course by @alejos7ven. It is about learning the Hearing the Blockchain. If you want to join then:



Join here: Domain Steem with JavaScript: Lesson #3 - Hearing the blockchain




Blue and Yellow Geometric Programmer Presentation (1).png

Designed with Canva

What uses would you give to the streamOperations method? (Not to mention those explained in the lesson)

The streamOperations method offers an enormously useful capability to respond to real-time events on the Steem blockchain. As from the name we can guess that it is the method which is used for the streaming data means it provides all the real-time happenings in the Steem blockchain. Here are some detailed use cases of the streamOperations:

1. Automated Content Curation

We can create a bot by using the streamOperations that monitors content published under certain tags such as #art, #music and aggregates them into a curated feed or newsletter.

We can filter for comment operations and check the metadata for the desired tags. We can store the relevant data such as author, permalink, title and periodically post a curated list of top content.

It helps the communities to discover the quality content efficiently and easily without manual work.


2. Spam Detection and Moderation

By using this method we can detect spamming behaviour by monitoring excessive or repetitive transactions such as comments, votes, or transfers from the same user.

We can use the streamOperations method to track comment and vote operations. Log user activity and analyze for patterns indicative of spam like identical comments across multiple posts.

So by using this method we can automate the moderation by keeping the platform clean and fostering a better user experience.


3. Real-Time Analytics Dashboard

We can create a live dashboard by using streamOperations that shows current trends such as the most active accounts, trending tags or high value transactions. It can be very useful for the real-time analytics.

We can use streamOperations to capture all the operation types such as votes, comments, transfers. We can update the dashboard with real-time statistics.

We can use it to give insights into Steem blockchain activity for community managers or data analysts.


4. Token Distribution Monitoring

We can monitor token distribution or rewards dispensed through the custom JSON operations on the blockchain. We can know where the tokens are being distributed from the specific amount or as a reward from the contest.

We can filter for custom_json operations and decode their data to identify token transfers or rewards dispensed.

So it helps the token issuers in monitoring and verifying successful distribution or claim logs in the blockchain.


5. Monitoring Account Transfers

We can use this method to track the financial transactions to monitor funds being moved for an account or a group of accounts.

Moreover we can filter the transfer operations, logging the sender, recipient, and amount of the tokens moved between the accounts. We can set up alerting on thresholds such as high-value transactions.

It is very useful for the treasury management. We can also track the donations happening in the blockchain.


6. Tag-Specific Community Engagement

We can respond to the users who post under a specific tag by automatically commenting on or upvoting their posts. If you have noticed that whenever a new account publishes a first post then the @steem.history account votes on that post. It is just because that the user has set his priority to vote based on the first published post.

We can track comment operations and scan for the specific tag. Leverage the data to programmatically post comments or votes to boost community engagement.

This provides community engagement and encourages interaction in relation to specified topics.


7. Decentralized App Development (dApps)

By using this method we can develop applications that are blockchain dependent such as live updates, games, reward systems or marketplaces.

We can use streamOperations as a core structure to observe and create specific logic functionalities such as when a predefined condition is met then we can trigger a desired action such as the dispersion of rewards.

It allows for real-time interactivity in blockchain based applications. As we have seen many gambling games in Steem blockchain which perform actions and when a specific action is met with the pre-defined conditions then a transaction is carried out.


8. Real-Time Contest Participation

We can automate contest entries or monitoring for challenges hosted on the blockchain. It can be done by monitoring the posts or entries published with the specific tag.

We can detect comment operations under a contest related post and log the participant details. Optionally, respond with confirmation comments or entries.

So it facilitates the management of large scale contests or campaigns in the blockchain.

9. Dynamic Blockchain Insights

We can track and display dynamic blockchain data. We can find out the trends such as the most voted posts busiest accounts or the highest value votes.

We can capture relevant operations like vote, comment and compute live metrics for user display. It attracts the users interested in the real-time blockchain data.


10. Account Activity Tracking

In order to monitor the activities of specific accounts we can use streamOperationssuch as whales or influencers to see their behaviour.

We can filter the operations where the voter, author, or from/to fields match the target accounts. We can log their activities and analyze the patterns. We can get insight into influential accounts' behaviour for strategic engagement.

All of these scenarios extend the ability of the streamOperations method. So we can use it for the real-time data collection and automation. We can also use it for the innovation purpose in the Steem blockchain.



Utilize the streamOperations method to identify the type of transaction, whether it is a comment, transfer, transfer_to_vesting, or withdraw_vesting. Use the data extracted from the above transactions and display a message in each scenario.

The streamOperations function in the Steem JS library is an important tool for the real time monitoring of blockchain operations. It monitors the blockchain operations as new blocks are being created. It listens to the Steem blockchain and provides all the operations contained in each newly added block in the ledger.

How It Works

  • The new blocks on the Steem blockchain are created approximately after every 3 seconds.

  • Each block of a blockchain carries out a stream of operations this can either be transactions or the actions conducted within the chain.

  • The streamOperations method reads out the continuous stream of the operation carried out on the blockchain in real time. This allows developers to respond or analyse data in the real time.

  • We can utilise this operation in this syntax steem.api.streamOperations(callback).

Here is how the streamOperations method can be used to identify specific transaction types such as comment, transfer, transfer_to_vesting and withdraw_vesting and print messages for each.

1. Detecting comment Transactions

image.png

This is the method of the streamOperation to detect the live comments happening in the Steem blockchain. It detects when a comment transaction occurs when someone creates a post or replies to an existing post.

Fields Explained:

  • author: The account that created the comment or post.
  • permlink: The unique identifier for the comment or post.
  • parent_author: Whether it's a reply (parent_author is set) or a top level post (parent_author is blank).
  • body: The content of the post or comment (snippet shown).

Real-world Use:

  • Track comments on a specific topic.
  • Keep track of new posts or activity from users.


comment-ezgif.com-optimize.gif

Here you can see the output of the comment detection transactions. We can see when the blockchain hears a new post by the author then it shows the data or whenever the user is creating any comment then it also shows the data.


2. Detecting transfer Transactions



We can use the streamOperations method to detect the transfers of the tokens happening on the Steem blockchain. A transfer transaction is when funds such as STEEM or SBD are transferred between the accounts.

Fields Explained:

  • from: The sender of the transaction.
  • to: The recipient of the transaction.
  • amount: The transferred amount along with the currency type.
  • memo: Optional text attached to the transaction for context.

Real-world Use:

  • Tracking payments, donations, or account activity.
  • Building tools to notify the users about the received funds.


transfer-ezgif.com-optimize.gif

Here you can see the transfers happening in the above gif. I run the script to detect the transfers between the accounts and we can see it has detected the transfers happening at that time.

Here we can observe that at that time STEEM was transferred from tipu to ien and similarly again from tipu to fozzy. It has displayed the amount of STEEM as well as the memo.


3. Detecting transfer_to_vesting Transactions


image.png

The streamOperations method is also useful for the detection of transfer_to_vesting transactions. A transfer_to_vesting transaction occurs when the funds are converted into Steem Power. We know that conversion of liquid Steems to the staked steem is known as the Steem Power and when this happens this transaction is known as transfer_to_vesting.

Fields Explained:

  • from: The account initiating the transfer to vesting.
  • to: The recipient account (or "Self" if funds are vested into the sender's account).
  • amount: The amount of STEEM being converted into Steem Power.

Real-world Use:

  • Monitoring users that are powering up (increasing their Steem Power).
  • Building tools for delegation or tracking vesting activity.


image.png

Here I have run this script to detect the transfer_to_vesting transaction. After running it I became able to capture a transaction of the transfer_to_vesting. If we see the details of the transfer_to_vesting transaction we can see that tipu transfered some amount of the liquid steems to the vesting to an other account which is zainejj. So it is how we can detect the transfer_to_vesting transaction by using the streamOperations method.


4. Detecting withdraw_vesting Transactions


image.png

As withdraw_vesting is also a real-time transaction of the blockchain so we can detect it as well by using the streamOperation method. Actually we filter the transaction by implementing the type of the transaction to withdraw_vesting and the script will only detect the withdraw_vesting transactions. A withdraw_vesting transaction happens when a user withdraws Steem Power into liquid STEEM (also known as "powering down").

Fields Explained:

  • account: The account which initiates the withdrawal.
  • vesting_shares: The number of Steem Power being withdrawn.

Real-world Use:

  • Tracking users powering down their Steem Power.
  • Trend analysis of liquidations within the blockchain environment.

image.png
image.png

As I have implemented transfer_to_vesting as well so when after making a testing account I performed the power up then it has detected the transaction as well as power up.

Then when the power down has started from the testing account then again the streamOperations method has detected that power down transaction and similarly when the power down is stopped then the transaction is also recorded. So it is how we can use this method to detect the withdraw_vesting transactions.


Advantages of Using streamOperations for These Functions

  1. Monitoring in Real Time: Can report activities such as comments, transfers, or even vesting change.
  2. Automation Triggering: Initiates bots or scripts on occurrence of detected activities (for instance, to warn users of transfers).
  3. Data Interpretation: Useful for analyzing trends in user actions, transaction activity, and other network behaviours.
    Each type of transaction has a specific use case, making the streamOperations utility applicable to various sophisticated blockchain-based application development.


Hear the blockchain and detect when you give a vote with your own account (start the bot and then give votes, and show how you detect it)

It is an interesting task to see the real-time changes of the transaction when we give vote to the users. It helps to identify that how the transaction are carried for the votes when we vote or un-vote the users. So I will again use streamOperations` method from the Steem JS library to detect the live votes because these votes are also the real-time transaction which happen in the blockchain.

I will filter the vote transactions from all other happening transactions so that we can only see the votes given at that time. Moreover we will specify the account as well so that we can only detect the real-time votes broadcasted to the users from that mentioned account.

image.png

Step-by-Step Explanation

1. Setting Up Steem JS

  • We know that he Steem JS library offers tools to interact with the Steem blockchain.
    And for this operation we will use it for the easy detections.
  • We can stream operations, fetch data, and interact programmatically by connecting to the blockchain.

How It Works:

  • The require("steem") statement imports the library.
  • The steem.api.setOptions({ url: 'https://api.steemit.com' }) sets the API endpoint used to connect to the blockchain.
  • Here https://api.steemit.com is a public node of the blockchain.

2. Listening to Blockchain Operations

Key Method: streamOperations

  • Streams every operation added to the blockchain in real time.
  • It's event-driven each time a block is added, operations within that block are processed.

How Operations Are Structured:

The operations parameter holds two things:

  • operations[0]: The type of the operation for example vote, transfer.
  • operations[1]: A data object carrying details specific to that operation.

Example of data in a vote operation

    {
      "voter": "steem_username",
      "author": "post_author",
      "permalink": "example-post",
      "weight": 5000
    }
  • streamOperations causes the callback to be called for each operation. We can filter by type.

3. Filtering on Operations having vote Word

  • The script should only process operations with the vote word.
  • Further narrow down to look for a match of the voter with your account name.

Logic in Code:

if (type === "vote" && data.voter === yourAccount) {
  • type === "vote" ensures only vote operations are processed.
  • data.voter === steemitAccount confirms the voter matches to the mentioned account.

So this bot can be used to detect the live votes from the account. You can see in the video as I am casting the votes they are being counted. The bot is returning the post and the vote weight. Whenever I vote the bot returns that my account has voted. So it is how I have used streamOperations to detect the real-time transactions of my votes and as I do cast the votes the bot is detecting them and showing the details and informing me that my account has voted.

Sort:  
Loading...