Skip to content

Instantly share code, notes, and snippets.

@wehmoen
Created July 14, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wehmoen/d583c521cccbceb6a5be4a6f8993fe01 to your computer and use it in GitHub Desktop.
Save wehmoen/d583c521cccbceb6a5be4a6f8993fe01 to your computer and use it in GitHub Desktop.
Claim all pending SCOT rewards
const fetch = require("node-fetch");
const steem = require("steem");
const account = "scot";
const wif = "5KYeFYCTtFAqoor4dBt4CDbLXnPyKbP2gmoPWpHtgspJ47MbWQh";
async function getTokensToClaim() {
let claimAble = [];
let token = await (await fetch('https://scot-api.steem-engine.com/@' + account, {method: 'GET'})).json();
for (let i in token) {
if (token[i].pending_token > 0) {
claimAble.push({
symbol: i,
token: token[i].pending_token / 1000 //works for PAL. not sure how to get the others precissions.
})
}
}
return claimAble;
}
function buildClaimTokenOperation(token) {
let json = [];
for (let i in token) {
json.push({symbol: token[i].symbol})
}
return [[
"custom_json",
{
required_auths: [],
required_posting_auths: [account],
id: "scot_claim_token",
json: JSON.stringify(json)
}
]];
}
(async () => {
let claimAble = await getTokensToClaim();
if (claimAble.length > 0) {
console.log(">", claimAble.length, "token to claim.");
console.table(claimAble);
let tx = buildClaimTokenOperation(claimAble);
try {
let result = await steem.broadcast.sendAsync({operations: tx}, {posting: wif});
console.log("> CLAIM SUCCESSFULL https://steemd.com/tx/" + result.id);
console.log("> Please wait at least 30 seconds before you run this script again.")
} catch (err) {
console.log(err);
console.log("> CLAIM FAILED:", JSON.stringify(err));
}
} else {
console.log("Nothing to claim.")
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment