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

in steemjs-s22w4 •  6 days ago  (edited)

Today we worked on the week 4 of Domain Steem with JavaScript: Lesson #4 - Broadcasting operations part 1: Transferring, and posting. by @alejos7ven. If you'd like to try this challenge click the link above and give it a try.


image.png
Image taken from Pixabay


1.png

  • 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, example app:'alejos7ven/1.0') [5 PTS]

In the code below I started by searching for specific operations, specifically the voting one vote. Once the needed operation was found I saved it in a variable. Now in a condition I checked if the vote was made by "ady-was-here", if that was true I logged that in the console to see it clearly and prepared the comment.

To create a proper comment we need a few things created, the first one is the comment itself which I held in the myComment variable, the permlink which I generated in myPermlink variable, you can see in the screenshot I commented how it was generated, and I added my name in the json_metadata.

Once everything was ready I added the steem.broadcast.comment with it's variables, also logged the error at the bottom just in case something goes wrong (which actually went wrong first time, I'll explain at the end of the post what I've done).

Also to make sure the broadcast won't fail I had to make sure the parent author, parent permlink, author, my custom permlink, my custom comment and json metadata were all added in also the title was left empty since this was a comment.


image.png

I've used the things taught in the current and previous lessons to create the code above, when run it logs everything and posts the comment, let's see a GIF with it in action.


Code_DTcqMLbbNu.gif


spacer.png






2.png

  • Use SteemWorld, Ecosynthesizer, or any other explorer to show the transactions you have created, leave link just like me. [2 PTS]

Out of the two tools presented I've picked steemworld to check the logs as I have used it before to check logs and stats. To test the code I've casted a vote on a post of @eight888, you can see the vote and the comment in the post here.


image.png

And if we expand the comment logs, we can see more details about the comment, specifically we can see the permlink that the code generated and the json metadata ady-was-here/1.0.


image.png

Also here is the link: https://steemworld.org/block/92041797/92041797-7?login=ady-was-here


spacer.png






3.png

  • Transfer 0.001 STEEM to @eight888 using Steem JS, add in the memo the title of this lesson. [3 PTS]

For the transfer task, I went to that you presented during the second week's task (https://github.com/steemit/steem-js/tree/master/doc#keys) and looked for the word transfer to find the correct method that needs to be used. Found steem.broadcast.transfer and how it can be used to create a transfer.


image.png

With these in mind, I moved everything in visual studio and started creating my transfer code.


image.png

I declared the wif outside the screenshot to avoid sharing my active key, other than that I declared a few variables, from, to, amount, memo all used to broadcast a transfer, with these you set the sender, receiver, amount sent and a memo.

Added the steem.boradcast.transfer method, added an error checking to see if it successfully or not, time to see it in action.


Code_VZQ0txG7N2.gif

And now if we check the @eight888's wallet and the logs on steemworld we can see that we have a transfer to that account.


image.png
image.png


spacer.png





That was it for this challenge, I mentioned in the first task that something went wrong well let's say I am following some people's vote to drain some of my voting mana while I don't have time to check posts, and I forgot I had them set on SteemWays. Once I ran my code my logs kept throwing me errors that I can't comment that fast and I need to wait 3 seconds before commenting again, and I kept checking the code what did I do wrong, where's the problem, all this time I was leaving comments because I was following some votes and casting votes as well. Luckily I managed to delete the comments, sorry for the spam.


image.png

In the end I'd like to invite @r0ssi, @titans and @sergeyk to take place in this week's challenge.

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

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...