You have definitely used very professional bots designed and developed by expert experts on Hive, but making your own bot to interact with the Hive blockchain gives you a great feeling.
Today I wrote a few lines of code to design a simple robot that does not need to install any tools! The image below is my designed UI for the bot, which shows my mindset in designing this bot:
I wanted the bot to find new posts and vote for them. Then I thought, do I vote for every post? So I decided to design it in such a way that it also checks the Reputation of the authors and only upvotes the posts of the authors who have the minimum required Reputation. Since I didn't want to install any tools I went for Hivejs. Of course, dhive is much better, but it was enough for a small test.
First, I created a new folder named Hive-bot, which contained two other folders named css and js. Then I created an index.html file in it.
UI design
First, I designed 6 inputs for the voter's hands to be open.
- 1th input: voter username in Hive
- 2th input: voter's private key
- 3th input: the minimum amount of voting power of the voter. I wanted to determine at least how much voting power we need to have in order to launch the bot. If the bot starts up and finds out that we don't have enough voting power, it will stop again to start working again automatically in the next cycle.
- 4th input: the minimum amount of reputation the author must have.
- 5th input: the weight of vote we want to give. This value is in percent and ranges from -100 to 100 percent.
- 6th input: amount of delay in automatic startup of the robot in minutes. I want the robot to start every 20 minutes and repeat the cycle until I give it a stop order. I set 1 - 240 minutes for it
- Two buttons, one to start the robot and the other to stop the robot.
Beautification with css
I went to the css folder and created a style.css file in it. Then I determined the amount of font, background, color and size, etc. of the html elements.
I went to the index.html file and link the css file to make the UI aesthetically complete. Now it was time to write the corresponding code.
js programming
I went to the js folder and created two files named config.js and script.js in it. Then I went back to the index.html file and appended both of the widgets to complete the UI.
I had to enter the initial settings in the config.js file. I wanted everything to be separate to make troubleshooting easier. First I had to determine which APIs I wanted to use. I gave priority to ecency and set the rest as alternatives.
Then I went to the script.js file to implement the basics of the program.
First I wrote a function. The task of this function was to compare the voting power at the very beginning of the work. If it's not to our desired level, the robot will stop at the beginning of the work.In the next step, the robot should get some of the newly published posts. I got 5 new posts here. Of course, it can be taken from the user as an input parameter, but I didn't see a need for now.
The bot then checks the author's reputation in a loop to find the first and most recent match. If the item is found, an upvote is given to the first item.
Another thing is, if the authors of all 5 posts do not have enough reputation, the bot will stop until the next cycle, but this process can be changed with a little coding.
Its complete code is as follows:
Although this simple robot was designed with basic coding, the pleasure of interacting with the Hive blockchain was very interesting. I haven't optimized this code yet, but it was very interesting as soon as an idea was created and implemented.
After Success Upvote!
I check It!
I enjoyed the challenge. This code is not yet optimized and many things can be added to it! Learning continues....
Posted Using LeoFinance Beta