 --- #### Repository e.g. https://github.com/steemit/steem-js #### What Will I Learn? - Create Simple Paid Voting Bot #### Requirements - Node.JS, [Here](https://nodejs.org/en/) - Steem Package (Install: npm install steem --save) #### Difficulty - Intermediate #### Tutorial Contents You will learn how to create paid voting bot. #### Curriculum - [Bot Build #1](https://utopian.io/utopian-io/@lonelywolf/build-bot-using-steem-js-1-upvoting-bot-by-friend-list-or-by-trending-posts) - [Bot Build #2](https://utopian.io/utopian-io/@lonelywolf/bot-build-2-auto-follow-bot) - [Bot Build #3](https://utopian.io/utopian-io/@lonelywolf/bot-build-3-auto-reward-claimer) - [Bot Build #4](https://steemit.com/utopian-io/@lonelywolf/bot-build-4-resteem-bot-with-friend-list) - [Bot Build #5](https://steemit.com/utopian-io/@lonelywolf/bot-build-5-curation-trail) - [SteemJS Tutorials #1](https://utopian.io/utopian-io/@lonelywolf/steem-js-tutorials-1-basics-validating-wif-key) - [NodeJS Tutorials #1](https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js) #### The Tutorial ### Step 1 - Setup Functions & Variables First of all, we need 2 variables for the user & wif. `Note`: I will use `guest123` user, this is a guest user that everybody can use [this user is steemjs official guest user] ``` const ACC_NAME = 'guest123', ACC_KEY = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg'; ``` `ACC_KEY` - the `wif`, private posting key. `ACC_NAME` - Account Name. we need two functions, one to calculate the voting weight and one to send the vote. ``` function calculateVotingWeight(amountPaid){ } function streamVote(url, amount) { } ``` we need those 2 functions to send the vote. one to calculate the voting weight and one to send the actual vote. ### Step 2 - Create The Functions first, we need to calculate the weight of the vote, because it's a simple bot we will check for sbd value, so for example, if the account has voting power that equals to 1$, 0.5$ or greater will equal to 100% vote. ``` const token = amountPaid.split(' '), tokenType = token.pop(), tokenValue = token.shift(); let weight; if (tokenValue >= 0.5){ weight = 100; } else if (tokenValue >= 0.1) { weight = 40; } else { weight = 20; } const steemToSbdRatio = 1.1; if( tokenType == 'STEEM') { return (weight * steemToSbdRatio) * 500; } else { return weight * 500; } ``` first, we need to split `0.001 SBD`(amount) to an only number `0.001`, then we use the `shift` function to delete the `SBD`/`STEEM` (the token type). then we check if the value of the sbd we received is greater than 0.5 if it is we send 100% vote, etc. and we create the variable `steemToSbdRatio`, `const steemToSbdRatio = 1.1;` this variable will give us the way to check how much value will steem paid vote equal to. for nowadays it's equal to around 1.1. now we need to check if the `token` type is STEEM or SBD, if it is STEEM we will multiply `weight` by `steemToSbdRatio` and then we will get the actual voting weight by multiply this by 500 `Note`: multiply by 500 will equal to around 50% vote, if you multiply it by 1000 it will be 100% but when someone using STEEM it will give more than 100% so the vote will not send. Now we need to create the function that `stream`/`send` the vote. first of all, we want to get the permlink and author from the memo (URL) and calculate the weight. ``` function streamVote(url, amount) { const memo = url.split('/'); const author = memo[4].split('@')[1]; const weight = calculateVotingWeight(amount); } ``` at first we split the memo(url) whenever there is slash(`/`), result: ``` [ 'https:', '', 'steemit.com', 'utopian-io', '@lonelywolf', 'bot-build-5-curation-trail' ] ``` we will get json variable with 5 variables, but we need only the name and the permlink. so, `memo[4]` is `@lonelywolf`, but for the vote function, we need only the name so we need to split it. so, `memo[4].split('@')[1];` we need `[1]` to get the second "split" and this is the name. so author is `memo[4].split('@')[1];` and then we need to get the voting weight so we're using the function we made before `calculateVotingWeight`. now we just need to send the vote, ``` steem.broadcast.vote(ACC_KEY, ACC_NAME, author, memo[5], weight, function(err, result) { console.log('Voted Succesfully, permalink: ' + memo[5] + ', author: ' + author + ', weight: ' + weight / 1000 + '%.', err); }); ``` `ACC_KEY` - Account posting private key `ACC_NAME` - Account name `author` - The post author `memo[5]` - The permlink `weight` - The voting weight ### Step 3 - Read Transfers And Send The Vote first of all, as the last Bot Build tutorial, we need to read the transfers, now we need to read the sbd/steem transfers. ``` steem.api.streamTransactions('head', function(err, result) { let type = result.operations[0][0]; let data = result.operations[0][1]; }); ``` this function gets every transaction that goes through the blockchain. `type` is the type of the transaction `data` is the data we get on the transaction, for our, it will be the sender, memo and amount. now we need to check if the type is `transfer` and if the receiver is our account. ``` if(type == 'transfer' && data.to == ACC_NAME) { console.log("Incoming request for vote from: " + data.from +", value: " + data.amount + "\n\n"); } ``` `data.to` is the receiver `data.from` is the sender `data.amount` is the amount now just stream the vote ``` streamVote(data.memo, data.amount); ``` `data.memo` is the memo the user send at the transfer (transaction) and here we're done! if you want to check if all works just use the streamvote function with your parameters, example: ``` streamVote("https://steemit.com/utopian-io/@lonelywolf/bot-build-5-curation-trail", "0.1 SBD"); ``` results: ``` Voted Successfully, permalink: bot-build-5-curation-trail, author: lonelywolf, weight: 10%. null ``` `null` - if you get this message it says that there are no errors if you don't want to get it just delete the `err` after the message. ```console.log('Voted Succesfully, permalink: ' + memo[5] + ', author: ' + author + ', weight: ' + weight / 1000 + '%.');``` **You can check the full work at my repl.it account and other bots that I create!** #### Proof of Work Done the work made in Repl.it, https://repl.it/@lonelywolf22/Steem-Bots-Paid-Upvoting-Bot user: https://repl.it/@lonelywolf22 GitHub: https://github.com/lonelywolf1 Utopian Tutorials GitHub Repository: https://github.com/lonelywolf1/Bot-Projects-SteemJS
author | lonelywolf |
---|---|
permlink | bot-build-6-simple-paid-upvoting-bot |
category | utopian-io |
json_metadata | {"tags":["utopian-io","tutorials","steemjs","bot","steem"],"image":["https://steemitimages.com/DQmPESUnnEycPYAh7HWVU8XfdU4ypzZXLDgjrGAQWpZsxXS/image.png"],"links":["/exit?url=https://github.com/steemit/steem-js","/exit?url=https://nodejs.org/en/","/exit?url=https://utopian.io/utopian-io/@lonelywolf/build-bot-using-steem-js-1-upvoting-bot-by-friend-list-or-by-trending-posts","/exit?url=https://utopian.io/utopian-io/@lonelywolf/bot-build-2-auto-follow-bot","/exit?url=https://utopian.io/utopian-io/@lonelywolf/bot-build-3-auto-reward-claimer","/exit?url=https://steemit.com/utopian-io/@lonelywolf/bot-build-4-resteem-bot-with-friend-list","/exit?url=https://steemit.com/utopian-io/@lonelywolf/bot-build-5-curation-trail","/exit?url=https://utopian.io/utopian-io/@lonelywolf/steem-js-tutorials-1-basics-validating-wif-key","/exit?url=https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js","/exit?url=https://repl.it/@lonelywolf22/Steem-Bots-Paid-Upvoting-Bot"],"app":"busy/2.4.0","format":"markdown","community":"busy","users":["lonelywolf","lonelywolf22"]} |
created | 2018-05-11 10:14:36 |
last_update | 2018-05-12 10:46:27 |
depth | 0 |
children | 5 |
last_payout | 2018-05-18 10:14:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 57.941 HBD |
curator_payout_value | 18.127 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6,681 |
author_reputation | 25,295,791,457,391 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,119,137 |
net_rshares | 16,561,046,918,508 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
guest123 | 0 | 397,643,896 | 100% | ||
techslut | 0 | 262,649,105,837 | 100% | ||
amirl | 0 | 82,327,169,347 | 100% | ||
alexzicky | 0 | 2,663,349,119 | 5.5% | ||
utopian-io | 0 | 16,106,341,585,039 | 11% | ||
thinkingmind | 0 | 3,666,519,167 | 100% | ||
lonelywolf | 0 | 299,827,393 | 100% | ||
abmoshe | 0 | 545,175,016 | 100% | ||
brupvoter | 0 | 95,164,851,633 | 3.94% | ||
headcorner | 0 | 3,607,286,459 | 100% | ||
beetlevc | 0 | 3,384,405,602 | 100% | ||
paul001 | 0 | 0 | -100% |
You got a 3.94% upvote from @brupvoter courtesy of @lonelywolf!
author | brupvoter |
---|---|
permlink | re-lonelywolf-bot-build-6-simple-paid-upvoting-bot-20180511t111203278z |
category | utopian-io |
json_metadata | {"app":"postpromoter/2.0.0"} |
created | 2018-05-11 11:12:03 |
last_update | 2018-05-11 11:12:03 |
depth | 1 |
children | 0 |
last_payout | 2018-05-18 11:12:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 64 |
author_reputation | 13,657,314,846,422 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,127,150 |
net_rshares | 0 |
Very interesting this tutorial. Put comments in the code to make it easier to understand. Good job! ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | portugalcoin |
---|---|
permlink | re-lonelywolf-bot-build-6-simple-paid-upvoting-bot-20180511t183907569z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-05-11 18:39:06 |
last_update | 2018-05-11 18:39:06 |
depth | 1 |
children | 1 |
last_payout | 2018-05-18 18:39:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 269 |
author_reputation | 598,828,312,571,988 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,163,073 |
net_rshares | 0 |
Thank you! My next contribution on the clock, I'll do that :)
author | lonelywolf |
---|---|
permlink | re-portugalcoin-re-lonelywolf-bot-build-6-simple-paid-upvoting-bot-20180512t054537806z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"busy","app":"busy/2.4.0"} |
created | 2018-05-12 05:45:36 |
last_update | 2018-05-12 05:45:36 |
depth | 2 |
children | 0 |
last_payout | 2018-05-19 05:45:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 61 |
author_reputation | 25,295,791,457,391 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,241,069 |
net_rshares | 0 |
Hey @lonelywolf **Thanks for contributing on Utopian**. We're already looking forward to your next contribution! **Contributing on Utopian** Learn how to contribute on <a href="https://join.utopian.io">our website</a> or by watching <a href="https://www.youtube.com/watch?v=8S1AtrzYY1Q">this tutorial</a> on Youtube. **Want to chat? Join us on Discord https://discord.gg/h52nFrV.** <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-lonelywolf-bot-build-6-simple-paid-upvoting-bot-20180511t200218142z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["lonelywolf"],"links":["https://join.utopian.io","https://www.youtube.com/watch?v=8S1AtrzYY1Q","https://discord.gg/h52nFrV","https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1"],"app":"steemit/0.1"} |
created | 2018-05-11 20:02:18 |
last_update | 2018-05-11 20:02:18 |
depth | 1 |
children | 0 |
last_payout | 2018-05-18 20:02:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 509 |
author_reputation | 152,955,367,999,756 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,174,935 |
net_rshares | 0 |
Super tutorial ! Thanks !
author | zonguin |
---|---|
permlink | re-lonelywolf-bot-build-6-simple-paid-upvoting-bot-20180512t074900815z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-05-12 07:49:06 |
last_update | 2018-05-12 07:49:06 |
depth | 1 |
children | 0 |
last_payout | 2018-05-19 07:49:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 25 |
author_reputation | 12,831,796,837,639 |
root_title | "Bot Build #6 - !Simple! Paid Upvoting Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 55,255,757 |
net_rshares | 0 |