Build Bot Using Steem-JS #1 - Upvoting Bot By Friend List Or by trending posts

in #utopian-io7 years ago (edited)

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 -

image.png

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

image.png

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

image.png


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

Sort:  

Coin Marketplace

STEEM 0.20
TRX 0.20
JST 0.034
BTC 89557.69
ETH 3064.76
USDT 1.00
SBD 2.96