Programming a Steem bot generating passive income S1E01

in bot •  6 years ago  (edited)

Creating content and voting on content get you a share of the Steem payouts. Content writing is hard and cannot be automated easily, but voting can definitively be automated.

bot.jpeg

This is the challenge of this post: creating a Steem bot that will automatically vote on new piece of content.

Bot tasks:

  • Build a database of user: search through followings and extend the search to the following's followings.
  • Find fresh content, i.e., not older than 7 days and and with more than 10 votes.
  • Vote as much as possible (minimum 3 seconds between 2 votes and at least 90% total voting power should be available)

Well, that bot is little bit challenging. Let's start with the baby version of it.

Baby version:

  • Fetch followers
  • Choose one follower randomly
  • Fetch latest post from random follower
  • Broadcast vote on latest post

Copy / paste the following code into a file named bot1.js

'use strict';

const steem = require('steem');

/* to be filled up */
const selfName = '';
const postingWif = '';

const eol = '\n';

steem.api.getFollowing(selfName, 0, 'blog', 100, (err, result) => {
  if (err) { throw err; }

  const followerUsernames = result.map(r => r.following);

  console.log('Followers:', eol);
  console.log(followerUsernames);

  const rndIdx = Math.floor(Math.random() * followerUsernames.length);
  const u = followerUsernames[rndIdx];

  console.log(eol, 'Chosen follower is:', eol);
  console.log(u);

  steem.api.getDiscussionsByBlog({tag: u, limit: 1}, (err, posts) => {
    if (err) { throw err; }

    console.log(eol, 'Post fields:', eol);
    console.log(Object.keys(posts[0]));

    steem.broadcast.vote(postingWif, selfName, u, posts[0].permlink, 1000, (err, result) => {
      if (err) { throw err; }

      console.log(eol, 'Vote broadcast:', eol);
      console.log(result);
    });
  });
});


This bot is written in JavaScript and it is to be run with the NodeJS run-time.

To run it, fire up your terminal, navigate to the directory containing bot1.js and type

node bot1.js


It is not working because you have to enter your name and posting WIF.

const selfName = '';
const postingWif = '';



Congratulations, you have run your first bot on the command-line and generate your first passive income on the Steem blockchain. Wait 7 days and obtain the payout!

Do try to run it and let me know in the comments if something is not clear. I'll write the next episodes based on the comments.

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!