Steem Bots - Curation Trail Bot

Words
218
Reading
1 min
Listen
Play
7y

image.png


Repository:

https://github.com/steemit/steem-js

What Will I Learn?

Requirements

  • Node.JS
  • SteemJS

Difficulty

  • Basic

Curriculum

The Tutorial

Hello guys and welcome back to the tutorials series SteemBots
so let's start, install steemjs libraray - npm install steem --save and open new document app.js

var steem = require('steem');

now add a few variables

//This User Is Official Steem-JS guest user, you can only post and vote through the Posting WIF.
const ACC_NAME = 'guest123',
    ACC_KEY = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg',
    TARGET = 'pharesim',
    MINIMUM = 10; //100% = 100000, 10% = 10000

the account name,
the account posting private key,
the target (who we're going to follow the votes with),
minimum is the minimum percentage we're giving.

add the RPC node.

steem.api.setOptions({ url: 'wss://rpc.buildteam.io' });

console.log("SteemBots @lonelywolf");
console.log("Curation Trail Bot Running...");
console.log("Waiting for votes from @" + TARGET);

now we need to add the 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 + '%.');
    });
}

because we already set the account name and key we don't need to take it from the function and all we do is to broadcast the vote to the steem blockchain with the author, permalink and weight and then send a comment to the console.

now we need to get the transactions

steem.api.streamTransactions('head', function(err, result){
    
});

now we need to get the type of the transactions and the data

    const type = result.operations[0][0];
    const data = result.operations[0][1];

now we're checking if the type is vote and if the voter is the target

if (type == 'vote' && data.voter == TARGET) {

}

now we need to check the voting weight

    console.log('@' + TARGET + ' Just voted now!');
    if (data.weight < MINIMUM*100){
        weight = MINIMUM*100;
    }else{
        weight = data.weight;
    }

now all we need is to send the vote.

    StreamVote(data.author, data.permlink, weight);

And here we have done, all you need to do is to run the script and wait for the voter and it will work perfectly!

Proof of Work Done

https://github.com/upmeboost-utopian

Have a great day!

Steem Bots - Curation Trail Bot | Ecency