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

This is week3 of @alejos7ven's SteemJS course, if you want to take a look or participate you can see the full post here Domain Steem with JavaScript: Lesson #3 - Hearing the blockchain.


22223232.png
Image taken from Pixabay

Let's get started.


1.png

  • What uses would you give to the streamOperations method? (Not to mention those explained the lesson) [2 PTS]

I started by running the code provided in the Task and see what data can I get from streamOperations and where could it be used.


Code_AgjW8DuDC7.gif

Judging by the data seen in the stream I would use this for the following uses:

  • Command Bot
    I would set up the stream to check each comment made and see if in the body there would be a certain command that could trigger the bot to do something (reply, upvote, follow, transfer etc)

Example: user "X" posts a comment anywhere with the command !joke, the stream checking the comments would find the comment, see the command and via code reply with a joke.

Something similar to @steem-seven and the !up command.

Here is how a comment listener would look like (GIF)


Code_v9rxXn4C7Y.gif

  • Transfer Alert
    Using the stream to check for transfers out of a given account and send notifications to a browser extension/discord bot to alert the user that a transfer has been made from his account. This way you can find faster if your account is compromised.

Example of checking outgoing transactions from my account.


Code_HGfajfJFok.gif

This could be extended to votes, power down, this way you find faster if someone has access to your account.


spacer.png






2.png

  • 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. [5 PTS]

I started this by checking each operation and see what data each one returns, so I setup my code to check only the specified operations and left it to run a couple of minutes to make sure I can get at least one of each operation, like this:


Code_fmhG6i65xH.gif

You can see in the GIF above the code used and me searching for the operations in the console to see if I have at least one.

Let's analyze each one:

  • Transfer
    Used to detect a transfer between two users/wallets, it returns from to amount and memo, basically it shows you the transfer made from someone, to someone with the amount sent and a memo that can be empty if the sender didn't add anything in that field.
    from the user that sent the transfer
    to the receiver of the transfer
    amount amount sent
    memo message added to the transfer


image.png

  • Comment
    Used to find Comments written by users, it has more data than a transfer, as it follow:

parent_author is the user that the comment has been replied to (either his post or comment)
parent_permlink is the link of the post
author is the author of the comment
permlink is the permlink of the comment
title this one is empty, comment's don't have titles
body is the comment itself, the text and markdown written by the user in the comment posted
json_metadata some metadata link + type and some version


image.png

  • Transfer_to_vesting
    Represents the transfer of SP to a user. It shows the user that sent the SP to which user it was sent to and the amount.
    from user sending the SP
    to user receiving the SP
    amount the amount sent


image.png

  • Withdraw_vesting
    Shows the start of a Power Down and the amount being powered down in VESTS.
    account the account name
    vesting_shares the amount of vests being powered down


image.png

And now let's change the code so it shows each operation with a message:


Code_lOy690LlIB.gif

  • For the comment part I print out the author and the permlink where the comment could be found.
  • For the transfer, I print out the from, to, amount and memo of the transfer
  • For the transfer_to_vesting, I print from, to and the amount
  • For the withdraw_vesting it's the account name and the vesting_shares

spacer.png






3.pg

  • 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) [3 PTS]

To detect the vote we need to look for the voting operation and if there is a voting operation and the voter name is the one we are looking for we can print that operation.


Code_CgoeugdJZS.gif

The above it's a GIF, wait for it the console will print the vote in a couple of seconds.

If we want to make it fancier we could adapt the code a little.


image.png

And another GIF


Code_lWvxSbYUB0.gif


spacer.png





That was it for this homework, in the end I'd like to invite @titans, @r0ssi and @mojociocio to try it!

Until next time, I am wishing you a great day!

Sort:  
Loading...

Congratulations, your post was upvoted by @supportive.

 4 days ago 

Solid work!
This article is now being scheduled for featuring on our WOX channel on Telegram, https://t.me/woxchannel.

Everyone is also invited to join ChatSteemBot on Telegram through this link: https://t.me/SteemBot or scan the QR Code on the flyer below. Thanks.


WOX Channel Flyer


World of Xpilar Telegram Channel | Chat SteemBot on Telegram

Everyone can support this initiative by delegating some SP to @sbsupport. Thanks in advance.

50SP | 100SP | 200SP | 500SP | 1000SP | 2000SP | 5000SP

Thanks for the invite!