<h2>Introduction
<p dir="auto">This tutorial will show you how to automatically follow users with a bot.
<p dir="auto"><span>First, you will need to set-up a NodeJS development environment. You can follow along the tutorial at <a href="https://steemit.com/javascript/@money-dreamer/nodejs-steemit-bot-tutorial" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://steemit.com/javascript/@money-dreamer/nodejs-steemit-bot-tutorial if you need to. That tutorial is a pre-requisite for this tutorial unless if you are already familiar with JavaScript, NodeJS, GIT and the Steemit API.
<p dir="auto"><span>You can view the full source code at: <a href="https://github.com/AdamCox9/Steemit-Follow-Bot" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/AdamCox9/Steemit-Follow-Bot
<p dir="auto">After getting your development environment set-up, copy and paste this code into a file named <code>follow_trending_authors.js and execute it like <code>node follow_trending_authors.js from a terminal as described in the previous tutorial. This will bring in all the functions from the Steem library, set the user/pass and create a log-in session to the Steem blockchain. The followingArray saves the new account so no duplicate following attempts.
<pre><code>var steem = require('steem');
var username = 'ENTER_USERNAME_HERE';
var password = 'ENTER_PASSWORD_HERE';
var wif = steem.auth.toWif(username, password, 'posting');
var followingArray = [];
<p dir="auto"><br />
<p dir="auto">Let's get the trending categories in our initial call. You can view the data printed to the console to become familiar with it.
<pre><code>steem.api.getState('/trending', function(err, result) {
console.log(err, result);
...
});
<p dir="auto"><br />
<p dir="auto">The <code>sleep function will time out the script so it does not make requests too fast:
<pre><code> function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
<p dir="auto"><br />
<p dir="auto">Create a function that will loop over the accounts in the trending tag:
<pre><code> async function followAccountsInTrending(result) {
var content = result.content;
var accounts = result.accounts;
for(var attributename in accounts) {
//console.log(attributename+': '+accounts[attributename]);
var following = accounts[attributename].name;
let followReq = ['follow']
followReq.push({follower: username, following: following, what: ['blog']})
const customJson = JSON.stringify(followReq)
console.log( followReq );
followingArray.indexOf(following) === -1 ?
followingArray.push(following) : console.log('This item already exists');
steem.broadcast.customJsonAsync(wif, [], [username], 'follow', customJson)
.then(console.log)
.catch(console.log)
await sleep(30000);
console.log( followingArray );
}
}
<p dir="auto"><br />
<p dir="auto">Create a function that loops over each category:
<pre><code> async function startFollowAccountsInTrending(result) {
var trending_tags = result.tag_idx.trending;
for(var attributename in trending_tags) {
console.log(attributename+': '+trending_tags[attributename]);
steem.api.getState('/trending/'+trending_tags[attributename], function(err, result) {
followAccountsInTrending(result);
});
await sleep(30000);
}
}
<p dir="auto"><br />
<p dir="auto">Initialize the function to loop through the categories:
<pre><code> startFollowAccountsInTrending(result);
<h2>Further Development
<p dir="auto">It will allow you to set parameters to select who to follow. Some of these parameters will be:
<ul>
<li>SBD/STEEM Balance
<li>Reputation
<li>Number of Followers
<li>Number of Following
<li>Total Author Rewards
<li>Total Curation Rewards
<p dir="auto"><span>You can view the full source code at: <a href="https://github.com/AdamCox9/Steemit-Follow-Bot" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/AdamCox9/Steemit-Follow-Bot
<p dir="auto">Proof of Work:
<p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmbuecZSkSZRYAtSt4NMiu3iyBkF28sRJFqCCs11ieivK9/image.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmbuecZSkSZRYAtSt4NMiu3iyBkF28sRJFqCCs11ieivK9/image.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmbuecZSkSZRYAtSt4NMiu3iyBkF28sRJFqCCs11ieivK9/image.png 2x" />
<p dir="auto"><a href="https://steemit.com/javascript/@money-dreamer/nodejs-steemit-bot-tutorial" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Previous | <a href="https://steemit.com/utopian-io/@money-dreamer/deep-follow-nodejs-steemjs" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Next
<p dir="auto"><br /><hr /><em>Posted on <a href="https://utopian.io/utopian-io/@money-dreamer/creating-follow-bot-w-nodejs" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian.io - Rewarding Open Source Contributors<hr /><p>
Thank you for the contribution. It has been approved.
This post has been moved to my mod queue by my supervisor.
Do you have any plans to expand the bot in future? There is a distinct lack of bots on Steemit that users can watch being built from the ground up to customise for themselves. If you do post more articles on this bot in future, you may consider putting them in the development category - it fits in much better there, and you will get more support from Utopian.io!
You can contact us on Discord.
[utopian-moderator]
I am working on my next bot now. I do plan on pushing out more of these tutorials/development projects. I'll add my next submission like this one to the development section!
Thanks! I look forward to working with the Utopian.io community.
Steem JavaScript Development Links
Is there a place where I can get a better big picture idea of what this is? It seems amazing, but I'm really curious to hear about the mechanics of it.
It is just an example of following the user accounts in the trending tags.
The idea is that if a user submits a post that makes it to the trending category, then that user should be worthy enough to follow.
Do you have any specific questions about the code?
Thanks for that. I think a cool bot would allow you to follow anybody who has commented upon your post. I don't know if it could somehow exclude bot comments.
Thanks for the awesome tutorial! :)
No problem at all! Expect more to come soon!
Hey @money-dreamer I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven 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
I copied everything to sublime text editor then executed in cmd.
No errors but in reality it didnt follow anyone.
You got a 68.97% upvote from @votebuster courtesy of @money-dreamer!
Sneaky Ninja Attack! You have been defended with a 1.88% vote... I was summoned by @money-dreamer! I have done their bidding and now I will vanish...Whoosh
This post has received a 2.54 % upvote from @upmyvote thanks to: @money-dreamer. Send at least 1 SBD to @upmyvote with a post link in the memo field to promote a post! Sorry, we can't upvote comments.
Thank you @money-dreamer for promoting this post together with https://steemit.com/budget/@jerrybanfield/introducing-steem-budget-proposals
@OriginalWorks
To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
You got a 0.76% upvote from @allaz courtesy of @money-dreamer!
This post has received a 0.40 % upvote from @buildawhale thanks to: @money-dreamer. Send at least 1 SBD to @buildawhale with a post link in the memo field for a portion of the next vote.
Steem WitnessTo support our daily curation initiative, please vote on my owner, @themarkymark, as a
STEEM WitnessYou got a 0.46% upvote from @upme requested by: @money-dreamer. Send at least 1.5 SBD to @upme with a post link in the memo field to receive upvote next round. To support our activity, please vote for my master @suggeelson, as a
You got a 100.00% upvote from @upmewhale courtesy of @money-dreamer!
You got a 11.43% upvote from @minnowvotes thanks to @money-dreamer!
This post has received a 3.52% upvote from @lovejuice thanks to @money-dreamer. They love you, so does Aggroed. Please be sure to vote for Witnesses at https://steemit.com/~witnesses.
You got a 4.20% upvote from @mercurybot courtesy of @money-dreamer!
I dig it, thanks bud
1.04% @pushup from @money-dreamer
50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP Don't delegate so much that you have less than 50SP left on your account.This post has received a 11.75% upvote from @msp-bidbot thanks to: @money-dreamer. Delegate SP to this public bot and get paid daily:
This post has received a 2.24 % upvote, thanks to: @money-dreamer.
Your contribution cannot be approved yet. See the Utopian Rules. Please edit your contribution to reapply for approval.
Your contribution is very good, but I would suggest moving it to Development section instead of Tutorials if the project is a new, coded from ground up.
You may edit your post here, as shown below:
You can contact us on Discord.
[utopian-moderator]