Steem Bots - Reward Claiming
Repository
What Will I Learn?
- You will learn how to build a bot that claims your rewards from the blockchain to your wallet
Requirements
- You will need NodeJS and the package steemJS
Difficulty
- Basic
Tutorial Contents
- first, you will learn how to make a basic server
- then you will learn how to use the claim function
- and you'll make a timer that makes a claim every 2 hours
Curriculum
The Tutorial
So because I already made a tutorial about that I will "skip" this part of making a basic server and I'll just give it.
const http = require('http');
const port = 80; //you can use any other port, like 3000 or something.
const hostIP = "localhost"; //or "127.0.0.1" which is better for you.
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-type', 'text-plain');
res.end('Hello World! this is my first project at node.js!');
});
server.listen(port, hostIP, () => {
console.log("Listen to port " + port);
});
just to make it easy, we're making a basic server and make a listen to the port (currently 80) and to our localhost server.
for this bot, we don't need anything better than that.
now we're going to make the claim function
so make a new function called ClaimMyRewards
with the vars account
and key
function ClaimMyRewards(account, key){
}
account
- the account name
key
- the private active key
now we need to get the information about the account
steem.api.getAccounts([account], function(err, result){
const sbd = result[0].reward_sbd_balance,
steem_liquid = result[0].reward_steem_balance,
sp = result[0].reward_vesting_balance;
console.log(sbd + " " + steem_liquid + " " + sp);
}
first, we're getting the account json variable(all of the information of the user) with the function getAccounts
then we're making a variable that called sbd
and we're getting the variable "reward_sbd_balance" this variable is the balance of the unclaimed rewards of SBD
same for steem and SP
then we're sending it to the console (the info)
now we're going to check if there are any rewards to claim
if(sbd == "0.000 SBD" && steem_liquid == "0.000 STEEM" && sp == "0.000000 VESTS"){
console.log("No Rewards To Claim!");
}else{//claiming rewards
}
if the sbd & steem & sp is equal to 0, that means there is nothing to claim
the console will tell us that there is nothing to claim
if there is anything to claim we'll make the claim
steem.broadcast.claimRewardBalance(key, account, steem_liquid, sbd, sp, function(err, result) {
console.log("Rewards of @" + account_name + " Have Been Claimed To The Wallet!");
console.log("Result:");
console.log(result);
});
so, we're using the functionclaimrewardsbalance
this function making a claim for the rewards that unclaimed on your account
it needs the key
and the account
and the steem, sbd, sp balance(amount) to make the claim.
if there are no errors it will send the comments to the console
now we're done with this function and we only need to make a timer that goes every 120m (2hrs) and uses this function
first make 2 variables, one called account
and second key
example :
const account = 'lonelywolf', key = 'P5K123N1UO23NU1B412U04N1U024';
note
: you need to use an Active Key and not Posting Key to make a claim!
now we just need to make the timer
go to the bottom of the function (claimmyrewards)
and paste that
setTimeout(function(){ClaimRewards(account, key)}, 120*60*1000);
it will make a timer 2 hours from now (when the function runs) and use the function again , it will make a loop.
now just at the bottom/middle of the script use this row:
ClaimRewards(account, key);
results:
- no rewards
0.000 SBD 0.000 STEEM 0.000000 VESTS
No Rewards To Claim!
- claimed rewards
0.000 SBD 0.000 STEEM 0.000000 VESTS
Rewards of @lonelywolf Have Been Claimed To The Wallet!
Result:
undefined
undefined means that no result found (or no errors).
- full code
const http = require('http');
const port = 80; //you can use any other port, like 3000 or something.
const hostIP = "localhost"; //or "127.0.0.1" which is better for you.
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-type', 'text-plain');
res.end('Hello World! this is my first project at node.js!');
});
server.listen(port, hostIP, () => {
console.log("Listen to port " + port);
});
const account = "lonelywolf",
key = "P5ASDNANDPOPASDNOPDN1231312";
ClaimRewards(account, key);
function ClaimRewards(account, key){
steem.api.getAccounts([account], function(err, result){
const sbd = result[0].reward_sbd_balance,
steem_liquid = result[0].reward_steem_balance,
sp = result[0].reward_vesting_balance;
console.log(sbd + " " + steem_liquid + " " + sp);
steem.broadcast.claimRewardBalance(key, account, steem_liquid, sbd, sp, function(err, result) {
console.log("Rewards of @" + account + " Have Been Claimed To The Wallet!");
console.log("Result:");
console.log(result);
setTimeout(function(){ClaimRewards(account, key)}, 120*60*1000);
});
});
}
Proof of Work Done
- GitHub: https://github.com/lonelywolf1
- The Tutorial will upload to my GitHub account when I will have access to my private computer (in the next 3 days)
have a good day, we're done for this tutorial!
this series will continue at the next week with more tutorials and with more content!
Thank you for your contribution @lonelywolf.
After analyzing your tutorial we suggest the following points below:
Thanks for your tutorial. We look forward to your next tutorial.
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? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
thanks fo your suggestions I'll apply them to the next tutorial!
I really appreciate that!
Have a good day, my next tutorial(s) will come today!
Thank you for your review, @portugalcoin!
So far this week you've reviewed 1 contributions. 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
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by TheLonelyWolF🐺 from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
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!