Introduction
This tutorial will show you how to automatically follow users with a bot.
First, you will need to set-up a NodeJS development environment. You can follow along the tutorial at 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.
You can view the full source code at: https://github.com/AdamCox9/Steemit-Follow-Bot
After getting your development environment set-up, copy and paste this code into a file named follow_trending_authors.js
and execute it like 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.
var steem = require('steem');
var username = 'ENTER_USERNAME_HERE';
var password = 'ENTER_PASSWORD_HERE';
var wif = steem.auth.toWif(username, password, 'posting');
var followingArray = [];
Let's get the trending categories in our initial call. You can view the data printed to the console to become familiar with it.
steem.api.getState('/trending', function(err, result) {
console.log(err, result);
...
});
The sleep
function will time out the script so it does not make requests too fast:
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Create a function that will loop over the accounts in the trending tag:
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 );
}
}
Create a function that loops over each category:
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);
}
}
Initialize the function to loop through the categories:
startFollowAccountsInTrending(result);
Further Development
It will allow you to set parameters to select who to follow. Some of these parameters will be:
- SBD/STEEM Balance
- Reputation
- Number of Followers
- Number of Following
- Total Author Rewards
- Total Curation Rewards
You can view the full source code at: https://github.com/AdamCox9/Steemit-Follow-Bot
Proof of Work:
Posted on Utopian.io - Rewarding Open Source Contributors
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
The @OriginalWorks bot has determined this post by @money-dreamer to be original material and upvoted it!
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.
To support our daily curation initiative, please vote on my owner, @themarkymark, as a Steem Witness
You 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 STEEM Witness
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
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: 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 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]