Domain Steem with JavaScript: Lesson #3 - Hearing the blockchain
Assalamualaikum my fellows I hope you will be fine by the grace of Allah. Today I am going to participate in the steemit learning challenge season 22 week 3 by @alejos7ven under the umbrella of steemit team. It is about Exploring the Steem API: Hearing the blockchain. Let us start exploring this week's teaching course.
What uses would you give to the streamOperations method? (Not to mention those explained the lesson)
Here are the use cases for the streamOperations
method:
1. Automated Content Curation
- Purpose: Help streamline the discovery and organization of valuable content.
- Applications:
- Monitor new posts containing specific tags or keywords (e.g.,
#art
,#technology
) and automatically compile them into a curated list for a newsletter or webpage. - Categorize content dynamically for community platforms or blogs.
- Monitor new posts containing specific tags or keywords (e.g.,
2. Blockchain Activity Monitoring
- Purpose: Track blockchain activity for personal, business, or community purposes.
- Applications:
- Keep tabs on specific accounts (e.g., high-profile influencers, businesses, or project wallets).
- Monitor the flow of tokens between accounts for audit trails or analytics.
- Detect operational patterns like commenting or posting frequency from popular users.
3. Real-Time Metrics and Analytics
- Purpose: Build dashboards to visualize blockchain activity in real-time.
- Applications:
- Measure voting power utilization trends (e.g., tracking whale account votes).
- Analyze block-by-block growth metrics, such as the number of new accounts created or the frequency of certain tags.
- Aggregate data on community engagement levels for hashtags or campaigns.
4. Transaction Validation and Security Alerts
- Purpose: Enhance security and transparency in blockchain interactions.
- Applications:
- Identify irregular voting patterns or mass upvotes/downvotes to prevent abuse (e.g., spam detection).
- Track wallet activity for large transactions and send alerts for high-value operations or potentially suspicious behavior.
- Create a decentralized alarm system for theft or fraud detection on specific accounts.
5. Game Mechanics Integration
- Purpose: Leverage blockchain interactions for real-time gaming.
- Applications:
- Reward players for specific actions, such as posting under certain hashtags or voting within time-limited windows.
- Track progress in blockchain-based games that rely on posting or commenting to move forward.
- Enable community-driven treasure hunts where users need to post clues or solve puzzles.
6. Decentralized Identity and Proof-of-Actions
- Purpose: Build tools for identity or activity verification without intermediaries.
- Applications:
- Authenticate users by monitoring specific transactions, like posting a unique code or tag to verify their identity.
- Record proof-of-participation in events, contests, or decentralized applications.
- Detect when users meet conditions to unlock rewards (e.g., posting with three unique tags).
7. Custom Workflow Automation
- Purpose: React dynamically to blockchain events.
- Applications:
- Send automatic thank-you messages to voters on your posts or replies.
- Set up a bot that auto-comments or replies to users based on predefined conditions (e.g., specific keywords in posts or comments).
- Trigger third-party integrations like sending emails or webhook notifications when certain events occur.
8. NFT and Tokenized Asset Monitoring
- Purpose: Integrate with blockchain-based digital assets.
- Applications:
- Track the creation, transfer, or sale of NFTs associated with Steem-based tokenization protocols.
- Build a notification system for users when new tokens or assets are created under specific categories.
- Analyze market activity for trading volumes or ownership changes.
9. Community Engagement and Rewards
- Purpose: Foster stronger community relationships through automation.
- Applications:
- Create reward programs where users are automatically thanked or incentivized for engaging with specific campaigns.
- Distribute tokens or upvotes to active contributors based on their posts or comments during events.
- Monitor sentiment within comments or posts to provide real-time engagement data.
10. Advertising and Sponsorship Tracking
- Purpose: Optimize blockchain interactions for marketing purposes.
- Applications:
- Detect posts or comments mentioning a brand or campaign and track the reach of these mentions.
- Reward users who create content promoting your products or services.
- Provide detailed insights into user engagement with branded hashtags or keywords.
11. Decentralized Governance and Voting Systems
- Purpose: Empower communities with blockchain-based decision-making.
- Applications:
- Monitor proposals or initiatives posted on the blockchain and tally community votes in real-time.
- Build dashboards to visualize community governance metrics (e.g., support levels for proposals).
- Track voting trends to analyze stakeholder engagement in decentralized organizations.
12. Historical Data Collection and Archival
- Purpose: Store and analyze blockchain data for strategic or historical purposes.
- Applications:
- Log real-time operations to an external database for offline processing or data visualization.
- Generate reports on blockchain trends, such as the rise and fall of specific hashtags or users’ influence over time.
- Preserve activity data for compliance or research purposes.
13. Social Signal Detection
- Purpose: Understand community behaviour and sentiment.
- Applications:
- Identify viral posts by monitoring comment and voting patterns within minutes of a post’s creation.
- Analyze trends in hashtags to determine emerging topics of interest.
- Track interactions (e.g., replies or votes) between specific accounts to map relationships or influence.
These use cases highlight the versatility of the streamOperations
method, providing opportunities to build impactful tools for analysis, automation and engagement across diverse domains.
Use the streamOperations method to detect the following types of transactions.
Here is the detailed information of detecting each transaction type (comment
, transfer
, transfer_to_vesting
, and withdraw_vesting
) using the streamOperations
method.
1. Detection of comment
Transactions
This code monitors the blockchain for comment
transactions, which can be either a new post or a reply to an existing post. By checking the parent_author
field:
- If
parent_author
is an empty string (""
), the operation represents a post. The code logs the author's name, post title, and permalink. - If
parent_author
is not empty, it signifies a reply. The code logs the author's name and the post (author and permalink) they are replying to.
This differentiation is essential for handling posts and replies uniquely.
In the working of this code some posts and replies are detected and they can be observed in the above picture.
2. Detection of transfer
Transactions
This code listens for transfer
transactions which represent STEEM or SBD token transfers between accounts. It detects the sender's account and the account of the receiver. Furthermore it detects the amount of the tokens transferred. It also detects the memo message sent while the transfer. In this way it provides the complete and clear information about the transfer
transactions.
In the working we can see it is detecting the transfer
transaction successfully while capturing the sender, receiver, amount of the tokens and the associated memo with that transaction.
3. Detection of transfer_to_vesting
Transactions
The transfer_to_vesting
transaction represents the process of converting liquid STEEM tokens into vested STEEM Power (SP). This can be done for the user’s account or for another account. The operation includes the name of the sender who starts the vesting transfer. It includes the account receiving the vested tokens (or null
if self-vesting). It also includes the amount of STEEM being converted. This code logs whether the transfer was to self or another user alongside the amount of STEEM being vested.
After running this code it successfully detected the transaction of the transfer_to_vesting
as it can be seen in the above picture as well as in the code picture in the output section. In both the transactions tipu account is transferring the amount of liquid steems to the vesting to another accounts.
4. Detecting withdraw_vesting
Transactions
The withdraw_vesting
transaction occurs when a user initiates a power down. In the power down the user converts STEEM Power (SP) back into liquid STEEM. The operation includes the account
from which the power down is started from the vested tokens to the liquid tokens. This transaction also includes the amount of the vesting_share
being withdrawn.
This code logs the account name and the amount of vesting shares being converted, providing a clear record of power down activities.
After trying again and again I became able to detect the vesting_withdraw
transaction from the blockchain. And I also came to know that vesting_withdraw
transactions are very rare. In the output terminal a transaction is detected where we can see the name of the user who started the power down which counted as the vesting_withdraw
. Moreover the amount of the vesting shares is also detected which was started power down. And when the user stopped the power down process it was also detected in the transaction.
Each of these examples focuses on detecting a specific transaction type and extracting relevant information. Together, they demonstrate how streamOperations
can be used to monitor and log various blockchain activities in real-time.
Hear the blockchain and detect when you give a vote with your own account
To detect votes cast by my own account using the streamOperations
method the bot listens for vote
transactions on the blockchain. When a vote operation is detected then it checks if the voter
field matches with my account name. And if it matches with my account it will return that my account has voted. Along with this information it will also fetch the post or comment to which I vote with the vote weight.
Below is the implementation and explanation:
After setting up the steem API to listen to the blockchain I have introduced a constant variable to store my steemit username because in the runtime it will not change and I will compare the voting transaction with this variable to detect when the vote is given from my account.
Then to listen to the transactions in the blockchain I have used the streamOperations
method because it is the method which will be used to detect the real-time transaction like vote in the blockchain.
Then from the number of transactions happening in the blockchain I have set the type of the transaction to vote
and then I have done comparison with my username through the constant variable which I defined at the start.
When all the conditions are true while listening to the blockchain then it returns that transaction and display in the terminal. It displays the voter, author, permlink, and weight.
After setting the account name and transaction type correctly I run the code and I started voting on the posts under the steemexclusive tag. As I was voting the posts the blockchain was listening to my action of voting and the code was printing the information of my vote in the terminal. As soon the vote transaction was completing it is informing that I have voted and then there is the detail of the transaction such as the author of the post, voted post and the vote weight.
This simple bot provides real-time feedback whenever you I a vote. So it is a useful tool for monitoring my own account's activity on the blockchain. If you want to make a bot just like this you can also make by using the streamOperations
and by using the Steem API.
So it is all about the streamOperations
method which is used to detect all the real-time transaction in the blockchain.
I invite @wilmer1988, @josepha, @wuddi to join this learning challenge.
Upvoted! Thank you for supporting witness @jswit.