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!