A Beginner’s Guide on How to Build a Steem Bot

Steemit is the first blockchain-based blogging and social media website that rewards its content creators with the cryptocurrency STEEM when they publish or curate content.

Bots were first introduced in the Steem ecosystem in 2016, and have since then come a long way. The most common Steem bot development is done for upvoting posts – in simple as well as complex conditions. A Steem bot developer can create an application over blockchain to perform tasks that are simple, but structurally repetitive. There can be certain pre-programmed conditions under which the bot functions and produces results. If too many conditions are levied, it creates complexity and the bot could run for long periods of time until the specific criterion is met and satisfied.

Steem bot development involves real-time automation over Steem blockchain with the help of simple APIs. The Steem bot developer can simply bootstrap an automated task with Steem without having much understanding about the node’s mechanism and tricky API.

Steem Bot Development – How to Build a Steem Bot
There are plenty of operations that you can simplify by learning how to make a bot for Steemit. In fact, you can even make money with a Steemit bot if you are adept at building one. This tutorial guides you on how to build a Steem bot that can perform the function of auto-voting.

Outline
An auto-voting bot can automatically upvote posts from the selected list of usernames. When new people join your platform, you can upvote their milestone to encourage them with the help of this Steemit bot.

What You Need
A plain text editor

Your private posting key – this is available in your wallet which can be accessed through the permissions tab on steemit.com. The private key feature allows the bot to vote.

Goals

specify a list of usernames (your friends)
connect to the Steem-js API
check when a new post is posted to the Steem network
check if the post belongs to any of your friends
send a vote to that post
Once that the basics are outlined for you, let us begin with the development:

 

Step 1: Set Up

For the purpose of this tutorial, we will have the bot run in the web browser (However, a more effective way to use this bot would be on the command-line, but this one is simpler and a good place to start from for a beginner).

Set up a blank HTML file and link it to the steem.js library. The library does most of the work as most of the commands are already present in it, talks to the Steem network, and means that we need to write very little code ourselves.

<html>

<head>

<script src=”https://cdn.steemjs.com/lib/latest/steem.min.js”></script>

<script></script>

</head>

<body></body>

</html>

You can go ahead and save this file as bot-tutorial.html. Although, if you run this file right now, it’ll only show you a blank screen.

Step 2 – Create a list of Friends

This step will enable you to store a list of names to the code. Whether the names should be up-voted or not can be decided later.

const FRIEND_LIST = [‘June’, ‘Zoe’, ‘Karen’, ‘Sarah’]

Once the bot is running, the list of names cannot be changed. So create an expansive list.

Step 3 – Connect to the Steem-js API

Connect to the Steem network and check all new transactions. Each block on the Steem blockchain holds transactions which can be anything – transfers, votes, comments, profile updates, and many more. Once we connect to the Steem network, we’re sent new data from the blockchain every few seconds.

The API is very consistent and follows the same set of rules.

Whenever you interact with the steem-js library, specify steem.api and then the action that you want taken. In some cases, actions need to provide extra information. This information is called arguments.

SteemBot constructor after declaration will provide some methods as events, which you can use to trigger different behaviors for different users. The first argument of every event method is always targetUsers and the second one is handler function. If you omit targetUsers the first one will be handlerfunction.

Targetusers could simply be a string with the username of a Steem account, or it could be an array of usernames. Omitting this parameter will require the event to trigger all users.

Step 4 – Check for the Names in Your Friend List
Once you’ve connected to the Steem-JS library, you need to check if the names that you get from the blockchain match those in your list of friends. To do this, create a function. Functions allow us to create blocks of code that we can reuse over and over.

The function can be created like this:

Friend(name){

return (FRIEND_LIST.indexOf(name) > -1);

}

Out function takes one piece of data ‘name’ and returns us a yes/no or a true/false answer.

With the help of this code we are taking our FRIEND_LIST and looking for the index (the position) of the name we entered. If the friend name that we ask for is in the list, it will say 1 or 3 (to show the position at which the name is at) for example if not it says -1. checking if the answer is > -1 gives us our true/false for friends.

Step 5 – Send Votes

Once the above steps are completed and the structure set up, the final step includes coding to send votes. For this, use the following command:

function sendVote(author, permlink){}

We can create another function which is slightly more complex and specific. In this function, the data we need is the author and the permlink. This function will specify the author and the post that you shall vote on.

function sendVote(author, permlink){

steem.broadcast.vote(ACCOUNT_POSTING_KEY, ACCOUNT_NAME, author, permlink, 10000, function(err, result) {

console.log(result);

});

}

With this function, you can enable a ‘steem.broadcast’. The data that you need to share includes the posting key, account name, the author, the link and a voting weight. Note the voting weight does not use percentages so 10000 is the same as 100%.

Finally, you can update the function to add the sendVote function instead of just a message. We’re taking the data from the transaction and using it in our send vote function.

That’s it! With the help of this simple tutorial on how to build a steem bot, your friend’s post will automatically get upvoted in your post.

You can use this simple exercise to create simple function and for steem bot development to help you in making your programs a lot more personalised. The bot will automate repetitive tasks of upvoting content each time without the need for your assistance. The bot will automatically start scrolling and fetching more content, then analyze everything and eventually upvote. Then it will refresh and do it again, and again, and again, and again.