Bot Build #5 - Curation Trail
Repository
e.g. https://github.com/steemit/steem-js
What Will I Learn?
- Create Curation Trail for any user you choose to follow
Requirements
- Node.JS, Here
- Steem Package (Install: npm install steem --save)
Difficulty
- Intermediate
Tutorial Contents
You will learn how to create your own curation trail and follow specific user votes
Curriculum
The Tutorial
Step 1 - Setup Variables & Functions
first we need some variables and functions.
(In this tutorial I'll use the guest account of the official steem-js, you can use it your own)
const ACC_NAME = 'guest123',
ACC_KEY = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg',
TARGET = 'pharesim',
MINIMUM = 10; //100% = 100000, 10% = 10000
ACC_NAME
- The Account Name
ACC_KEY
- The Account Posting Private Key
TARGET
- Your Target User
MINIMUM
- The Minimum Voting Weight, Most Of The Times You Should Need At Least 10%.
function StreamVote(author, permalink, weight) {
}
//Optional
function StreamFollow(following){
}
Note:
The Follow Function Is Only Optional! If You Don't Want To Follow Every Vote Just Remove The Function And Not Use It
streamVote
- vote
streamFollow
- follow
Step 2 - Fill The Functions
Before we go for the real trail we need to make the functions work.
-Voting Function-
function StreamVote(author, permalink, weight) {
steem.broadcast.vote(ACC_KEY, ACC_NAME, author, permalink, weight, function(err, result) {
console.log('Voted Succesfully, permalink: ' + permalink + ', author: ' + author + ', weight: ' + weight / 1000 + '%.');
});
}
steem.broadcast.vote
- sending vote with the author, permlink, weight and the account.
ACC_KEY
- Account Private Posting Key
ACC_NAME
- Account Name
author
- The Post Author
permalink
- The Permalink(permlink) Of The Post
weight
- The Voting Weight
-Follow Function [Optional!]-
function StreamFollow(following){
var json = JSON.stringify(
['follow', {
follower: ACC_NAME,
following: following,
what: ['blog']
}]);
steem.broadcast.customJson(ACC_KEY, [], [ACC_NAME], 'follow', json, function(err, result) {
console.log("Follow: " + following + " Successfully!");
});
}
json
- This Variable will save the follower(Account Name) and the following(the author), you need this variable for the customJson function
steem.broadcast.customJson
- this function sending custom json requests, for example if you want to follow or reblog.
ACC_KEY
- Account posting private key
ACC_NAME
- Account Name
follow
- The 'mission'
Step 3 - Creating The Curation Trail
first of all, we want to get every vote streamed through the blockchain.
steem.api.streamTransactions('head', function(err, result){
});
this function gives every transaction going through the steem blockchain.
const type = result.operations[0][0];
const data = result.operations[0][1];
type
- the type of the transaction
data
- the data of the transaction
now we need to check if the type is vote
and if the account is our target
if (type == 'vote' && data.voter == TARGET) {
console.log('@' + TARGET + ' Just voted now!');
}
if it's true we can send a message so we know that our target voted now.
now we just need to check the voting weight and to send the vote and follow the user(again the follow is optional)
if (data.weight < MINIMUM*1000)
weight = MINIMUM*1000;
else
weight = data.weight;
StreamVote(data.author, data.permlink, weight);
//Optional
StreamFollow(data.author);
first line check if the data.weight
(the voting weight of the target) is less than our minimum if it is lower weight
equals to the minimum1000 (weight in an integer is the percentage1000, for example, 10% = 10,000)
if the voting weight is higher weight
equals to the target voting weight.
then we streaming the vote and follow the author.
Note:
because it's getting the most recent vote it will continue forever until you will close the script.
results [from repl.it]:
Curation Trail Bot Script Running...
Waiting for votes from @pharesim
@pharesim Just voted now!
Voted Succesfully, permalink: my-pictures-my-graduation-2-4571a1c4b6684, author: fussyde, weight: 10%.
Follow: fussyde Successfully!
if you want to see the full code you can check the repl
at repl.it.
links at Proof of Work Done
.
Proof of Work Done
the work made in Repl.it, https://repl.it/@lonelywolf22/Steem-Bots-Curation-Trail
user: https://repl.it/@lonelywolf22
GitHub: https://github.com/lonelywolf1
Utopian Tutorials GitHub Repository: https://github.com/lonelywolf1/Bot-Projects-SteemJS
Thank you for your contribution.
Overall I liked your work, I would though suggest the following improvements for your future contributions:
Looking forward to your upcoming tutorials.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hi, thanks for the tips it's really helpful I will look for it on my next contribution!
thank you!
You just received a 38.00% upvote from @honestbot, courtesy of @lonelywolf!
great :D
thank you
Hey @lonelywolf
Thanks for contributing on Utopian.
We're already looking forward to your next contribution!
Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!