Domain Steem with JavaScript: Lesson #3 - Hearing the blockchain
Image source: Pixabay
Hello everybody and a Happy New Year!
This post represents the homework for week 3 of Domain Steem with JavaScript course by @alejos7ven, you can check it here.
Let get started.
Task 1: What uses would you give to the streamOperations method? (Not to mention those explained the lesson) |
---|
streamOperations method is used to see real-time operations happening in the blockchain. Running the code provided in the lesson, we can see different types of operations that happen. Using all this information, the code can be altered to our liking.
For example we can create a bot that can detect and upvote posts that fit a certain criteria, that have specific tags, or that contain specific words in the title or body. In this case, I am searching for comments or posts that contain the word 'diary' in the body:
Another good use for this can be to track transfer
operations to a specific account in real time in case of a charity event and can also thank the users who donate.
Can also be used to track comments that spam or use offensive words and get an overview of the accounts. It can look something like this:
Of course, the uses for this method are endless and it's up to our coding skills what we can create and use it for.
Task 2: Use the streamOperations method to detect the following types of transactions: comment, transfer, transfer_to_vesting, withdraw_vesting. Analyze the information contained in these transactions and show a message for each case. |
---|
Using a modified variation of the code provided in the course, we can extract the necessary transaction types. Here is how the code looks like:
Since further in this task I want to extract only the comments left by my account, I declared a constant that extracts the type and data from each operation.
Analyzing the types of transactions:
Comment
Can be used to find comment left by users. The code can also be adjusted to find specific comments left by specific users, also comment can show a post someone makes. The information we are provided with is:
parent_author
- the user/author of the original post or comment which I reply to
parent_permalink
- link of the post
author
- the user that leaves the comment
permlink
- the link of the comment
title
- is the title of the post or empty for comments
body
- the content of the comment
json_metadata
- app version and metadata
The code used for the outcome you see above is this:
Transfer
This type of transaction can be used to see transfers between users or wallets. The available information is:
from
- the user that initiates the transfer
to
- the receiver of the transfer
amount
- the amount sent
memo
- the message accompanying the transfer
Transfer_to_vesting
Is used to see information about a SP transfer between users. The available data is:
from
- user who initiates the transfer
to
- receiving user
amount
- amount transferred
- Withdraw_vesting
Can be used to see the amount of vests a user is powering down
account
- account name
vesting_shares
- amount that is powered down
Task 3: 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) |
---|
To detect votes in the blockchain, we can search for vote
types of transactions. By running a generic code for this type, similar to what was done in task 2 for transfer
, we can find out what information is provided to us.
The result of the code above, is this:
As we can see, the available data is:
voter
, author
, permlink
and weight
. Using this information, we can rewrite the code to search for votes given by my account:As always, thank you for reading and I'd like to extend an invitation to @r0ssi, @radudangratian and @cmalescov to take part in this.