Bot Build #3 - Auto Reward Claimer
What Will I Learn?
- Build Auto Rewards Claimer Bot
Requirements
- Node.JS, Here
- Steem Package (Install:
npm install steem --save
)
Difficulty
- Basic
Tutorial Contents
In this tutorial, You going to build auto rewards claimer, a bot that's loop every 30 minutes and claiming your rewards from the account.
Curriculum
The Tutorial
Step 1 - create a function
you need to create a function to be able to get this function loop every 30 minutes, so we want to make a function called ClaimRewards
function ClaimRewards(account_name, wif){
}
this will give us the ability to call the function when we set up the loop,
account_name
- the account that we claiming the rewards.
wif
- the private posting key of the account
Step 2 - Get Account Information (sbd, steem, and sp that we need to claim)
steem.api.getAccounts([account_name], 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);
}
sbd
- the amount of rewarded sbd we need to claim.
steem
- the amount of rewarded steem we need to claim.
sp
- the amount of rewarded vesting (invested steem) or Steem power we need to claim.
the result of the console
0.000 SBD 0.000 STEEM 0.000000 VESTS
currently, I have no rewards to claim so It's giving 0
.
Step 3 - Check if there are rewards to claim
to check if there are rewards we need to check for "0" value in any type of reward.
if(sbd == "0.000 SBD" && steem_liquid == "0.000 STEEM" && sp == "0.000000 VESTS"){
console.log("No Rewards To Claim!");
}else{//claiming rewards
}
at the else, we will claim the rewards at the next step
result
0.000 SBD 0.000 STEEM 0.000000 VESTS
No Rewards To Claim!
Step 4 - Claiming the rewards
when we have all of the variables we need we can now claim the rewards
steem.broadcast.claimRewardBalance(wif, account_name, 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);
});
wif
- the private key of the account
account_name
- the account that we claiming the rewards.
sbd, steem_liquid, sp
- the reward values as sbd, steem liquid and steem invested(Sp).
and then we sending the information to the console.
result
Rewards of @lonelywolf Have Been Claimed To The Wallet!
Result:
undefined
if you get undefined
and the rewards claim value is 0.000 SBD 0.000 STEEM 0.000000 VESTS
it's okay because there are no rewards and the function need more then 0
to claim the rewards.
Step 5 - Set up the timer(loop)
at the end of the claimRewardBalance
function, we want to add this line
setTimeout(function(){ClaimRewards(account_name, wif)}, 30*60*1000);
wif
- the private key of the account
account_name
- the account that we claiming the rewards.
30*60*1000
- 30 is the minutes (you can change it to 60 or 120 for 1 or 2 hours), 60 is the seconds, 1000 is the milliseconds.
full code of the function
function ClaimRewards(account_name, wif){
steem.api.getAccounts([account_name], 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(wif, account_name, 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);
setTimeout(function(){ClaimRewards(account_name, wif)}, 30*60*1000);
});
});
}
Step 6 - Claim The Rewards
at the start of the script create 2 variables, the wif
and the account_name
const account_name = "lonelywolf", wif = "5XXXXXXXXXXX";
and then you can claim the rewards and every 30 minutes (or what you changed it to) it will claim the rewards again.
ClaimRewards(account_name, wif);
if all done correctly you will get this results
no rewards to claim
0.000 SBD 0.000 STEEM 0.000000 VESTS
No Rewards To Claim!
reward claiming
0.000 SBD 0.000 STEEM 0.000000 VESTS
Rewards of @lonelywolf Have Been Claimed To The Wallet!
Result:
undefined
if you have something to claim undefined
will not be there and you will get a different result.
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord. [utopian-moderator]
Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.
[utopian-moderator]
Thank you for the contribution. It has been approved.
Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.
[utopian-moderator]
Hey @lonelywolf I am @utopian-io. I have just upvoted you!
Achievements
Utopian Witness!
Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x