Steem Bots - Curation Trail Bot

in #utopian-io5 years ago

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!

Sort:  

Thank you for your contribution @lonelywolf.
After reviewing your tutorial we suggest the following points listed below:

  • Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

  • On the topic "What Will I Learn", you didn't write anything. Before publishing a tutorial it's essential to read it again to check for errors in the contribution.

  • Your contribution is poorly detailed. It's important to explain in detail what you are developing so that the reader reaches the end of your tutorial and fully understands what you have taught.

  • It would be interesting to have some GIF to demonstrate the results in the terminal.

Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you for your review, @portugalcoin! Keep up the good work!

Hi @lonelywolf!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @lonelywolf!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.32
TRX 0.12
JST 0.034
BTC 64837.84
ETH 3174.86
USDT 1.00
SBD 4.17