Domain Steem with JavaScript: Lesson #4 - Broadcasting operations part 1: Transferring, and posting

in steemjs-s22w4 •  6 days ago 


javascript4.jpg
Photo taken from Pixabay

Hello everybody!
This post represents the homework for week 4 of Domain Steem with JavaScript course by @alejos7ven, you can check it here.

Let get started.

Task 1: Create a bot that detects when you vote for someone else's publication, when detecting your vote creates an automatic comment on that publication you voted for (the app that created your comment should be called your username and version 1.0

To create a bot that will leave automatic comments when detecting a vote, we need to use the steem.broadcast.comment method and streamOperations, discussed in last week's topic.

The steem.broadcast.comment method uses some specific parameters that we need to take into account:

  • wif: the private active key
  • parentAuthor: the user/author of the original post
  • parentPermlink: 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
  • jsonMetadata: app version and metadata

For our task, we can write some of the information as constants:

  • wif: my active private key
  • author: mojociocio
  • title: empty because I leave a comment
  • body: "Thank you for your amazing post! \n\n---\n*This comment was made automatically"
  • jsonMetadata: app:'amojociocio/1.0'

Now, let's take a look at the code:


image.png

At the top of the code, I imported the Steem library so I can interact with the blockchain and do this task. I also have a constant username that stores my account name, "mojociocio" in this case, and also the private active key, which I left empty for this photo.

I am using the steem.api.streamOperations method to listen the blockchain for votes, specifically made by my account. When detecting.

After a vote is identified, a specific text appears in the console that lets us know who is the author of the post and the posts permlink.

The next step is to post the comment by using the steem.broadcast.comment method, which uses the parameters set like: private active key, the author of the parent post, the posts permalink, the username of the author, permalink of the comment, title (set to empty because it's a comment), the body of the comment and the JSON metadata.


image.png

Error handling was also implemented to catch any error that may appear during the execution of the code, be it in the streemOperations or posting the comment.


image.png


image.png

Task 2: Use SteemWorld, Ecosynthesizer, or any other explorer to show the transactions you have created, leave link just like me.

The 2 mentioned tools can be used to see information about different types of transactions. In my case, I am more familiar with SteemWorld so that is what I used for this task.

By checking the "Account Operations", we can see everything that is done on the account. Here you can see 2 votes and the automated comments left immediately after.


image.png

When checking the details of a certain action, we can see the Block Details, Transactions and Virtual Operations. For this task, we need to look at the Transactions tab and see the information we put in the code: author, title which is empty, body and json metadata


image.png
https://steemworld.org/block/92039884/92039884-5

Task 3: Transfer 0.001 STEEM to @eight888 using Steem JS, add in the memo the title of this lesson.

To do a transfer, we need to use the steem.broadcast.transfer method, which needs the following data:

  • wif: represents the active private key for the from account
  • from: account name of the sender, without @ symbol
  • to: account name of the receiver, without @ symbol
  • amount: the amount of the asset we want to transfer. It requires 3 decimals and the symbol STEEM/SBD
  • memo: the message that will appear in the transaction


image.png

Now, let's look at the code:


task 3 code.png

As always, we need to import the Steem library at the beginning of the code so we can interact with the blockchain.

I declared all the needed information for the steem.broadcast.transfer method within constants. For security reasons, the code above does not contain my private key.

  • wif: my active private key
  • from: mojociocio
  • to: eight888
  • amount: 0.001 STEEM
  • memo: Domain Steem with JavaScript: Lesson #4 - Broadcasting operations part 1: Transferring, and posting

I also log any error that may appear when executing the the function and display it in the console.

The result of running the code can be seen below:


task 3 success.png

The transaction can also be checked of SteemWorld via this https://steemworld.org/block/92005688/92005688-4 and also in the picture below:


task 3 steemworld.png

As always, thank you for reading and I'd like to extend an invitation to @ady-was-here, @radudangratian and @cmalescov to take part in this.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...