Repository:
https://github.com/steemit/steem-js
What Will I Learn?
- You will learn how to see new transactions that goes through the blockchain in real-time
- You will learn how to "follow" specific user votes and vote after him
- You will learn how
Requirements
- Node.JS
- SteemJS
Difficulty
- Basic
Tutorial Contents
You're going to learn how to make automatic curation trail that follows after a target
account and sending votes after him.
Curriculum
- Steem Bots - Auto Follower Bot [SteemJS & NodeJS] - Begginer Tutorial
- Steem Bots - Upvoting By Payment [NodeJS & SteemJS] - Basic Bot
- SteemBots - Reward Claiming
- SteemJS #1
- NodeJS #1
The Tutorial
first create few variables -
const ACC_NAME = 'guest123',
ACC_KEY = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
var min_pw = 98, // minimum power to make a vote
weight = 10*100, // weight for vote (10 = percentage)
TARGET = "lonelywolf"; // the target of the curation trail (who we're following on the trail)
the account name and key is the public steem.js account (only private posting key!)
so first make 2 functions, one for calculating the voting power and second to stream the vote
- vote stream
function streamVote(author, permalink, weight) {
steem.broadcast.vote(ACC_KEY, ACC_NAME, author, permalink, weight, function(err, result) { //"broadcast" the vote to the blockchain
if(err)
throw err;
console.log('Voted Succesfully, permalink: ' + permalink + ', author: ' + author + ', weight: ' + weight / 1000 + '%.');
});
}
so easy enough, we're taking the author, permlink and weight of the vote
sending a broadcast to the blockchain and make the vote.
than sending a comment to the console.
function getVoteWeight(acc_name){
steem.api.getAccounts([acc_name], function(err, res){
var secondsago = (new Date - new Date(res[0].last_vote_time + "Z")) / 1000,
vpow = res[0].voting_power + (10000 * secondsago / 432000);
vpow = Math.min(vpow / 100, 100).toFixed(2);
return vpow;
});
}
at this function we're checking the vote weight,
we're checking it by the account name, simply we're taking the last_voted_time, the vote power and calculate it.
you can check the full code to see it full detailed.
steem.api.streamTransactions('head', function(err, result){
const type = result.operations[0][0];
const data = result.operations[0][1];
if (type == 'vote' && data.voter == TARGET) {
console.log('@' + TARGET + ' Just voted now!');
if(getVoteWeight('lonelywolf') < min_pw){
console.log("Your voting weight is less than the minimum: " + min_pw +", so the vote have not been sent!");
}else{
streamVote(data.author, data.permlink, weight);
}
}
});
now we need to listen for new transactions that goes through the blockchain, so we get the type and the data from the result operations.
then we check if the type of transaction is vote
and we check if the voter
(the account that made the vote) is our TARGET
(the account we're following.
if it is we're checking if the weight is higher then the minimum power (so we're checking for example if the vote weight is higher than 84)
if it is, we're sending the vote, if not we're sending comment to the console.
now we can just run the script and let it run forever.
results:
=> [Function]
@lonelywolf Just voted now!
Voted Succesfully, permalink: liquid-steem-report-nov-7-2018, author: socky, weight: 10%.