Build Bot Using Steem-JS #1 - Upvoting Bot By Friend List Or by trending posts
What is steem-js
Steem-JS is a javascript package that gives you the option to work with steem blockchain through javascript.
What Will I Learn?
Write here briefly the details of what the user is going to learn in a bullet list.
- Build Upvoting Bot With SteemJS
Requirements
- Node.JS, Here
- Steem Package
Difficulty
- Basic
Tutorial Contents
In this tutorial, you will build steemjs upvoting bot in just a few minutes.
This will give you the option to make a "friend list" to upvote your friends,
in the second case you will build a trending post upvoting bot.
Curriculum
The Tutorial
For Friend list we need to make our friend list, we need to make json variable with the friend's name:
const friends = [
"lonelywolf",
"atukh09",
"yairdd"
];
to add friends just put ,
and add the username.
to make the console looks good you can design it for yourself, this is my example
console.log("Total Friends: " + friends.length + " - Friends List");
console.log("----------------------------------------------");
console.log("Note: close the CMD and open again to give upvotes again.");
console.log("----------------------------------------------");
console.log(friends);
console.log("----------------------------------------------");
friends.length
- giving the number of friends inside the json variable.
friends
- sending the json variable - ['lonelywolf', 'atukh09', 'yairdd']
result
-
now we want to make a loop for the number of friends we have -
for(var i=0; i<friends.length; i++){
if(!!err)
throw err;
}
this will make a loop by the friend's length, for me, it's 3
, so it will loop from 0 to 2.
now we need to get the last post from the friend (you can limit it to whatever you want, I limited it for 1, last post)
steem.api.getDiscussionsByBlog({tag: friends[i], limit: 1}, function(err, result){
const wif = "XXXXXXXXX",
voter = "lonelywolf",
author = result[0].author,
permlink = result[0].permlink,
weight = 1000;
steem.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
console.log("Your Friend " + author + " Got " + weight/100 + "% Upvote For his last post.");
});
});
tag
- for this function is your username.
limit
- the limit of posts you get from the user
wif
- the private active key, this key can found at the wallet permissions
, we need it to send the vote.
voter
- your name at steemit, my is "lonelywolf".
author
- the friend name, we're getting it from the function.
permlink
- the permalink of the post we're voting on, we're getting it from the function.
weight
- the weight of the vote, multiply the percentage by 100 to get the weight integer, for example, 10% = 1000.
now we're broadcasting the vote with the variables and sending a message with the friend name and the vote weight (calculating by integer weight(1000) divide by 100 = 10%).
the result
Voting By Trending posts
to make the bot voting by trending posts change the function to getDiscussionsByTrending, you can get a full explanation on my steem-js tutorial #2, link at the top of the post.
code
steem.api.getDiscussionsByTrending({tag: "photography", limit: 1}, function(err, result){
if(!!err)
throw err;
result.forEach(function(row){
const wif = "XXX",
voter = "lonelywolf",
author = row.author,
permlink = row.permlink,
weight = 1000;
steem.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
console.log("The account " + author + " Got " + weight/100 + "% Upvote For his post.");
});
});
});
tag
- in this case, it's the category of the post, for this example is photography
limit
- the post count.
result.forEach
- we make a loop to send the votes (we need it for voting more than 1 post).
wif
- the private active key, this key can found at the wallet permissions
, we need it to send the vote.
voter
- your name at steemit, my is "lonelywolf".
author
- the friend name, we're getting it from the function.
permlink
- the permalink of the post we're voting on, we're getting it from the function.
weight
- the weight of the vote, multiply the percentage by 100 to get the weight integer, for example, 10% = 1000.
result
To run the bot use the command
node bot.js
change bot.js
to your script name.
you can open it anytime to make a new vote to your friends or on the trending posts
suggestions to modify the script
make a cycle of votes so you vote every time your friend is uploading a new post
make a 30 minute(or other time) cycle to upvote for trending posts
Next Tutorial
- Build Auto Follow Bot, The tutorial released click Here
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank You!
You got a 16.83% upvote from @luckyvotes courtesy of @lonelywolf!
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by TheLonelyWolF🐺 from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
Hey @lonelywolf I am @utopian-io. I have just upvoted you!
Achievements
Utopian Witness!
Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Thanks!
Is this tutorial really works?
anyone tried this?
Does it works?
It's work perfectly.