Javascript (NodeJS) Function to Get the Downvote Power of Account on Steem Blockchain
Accounts on Steem Blockchain have daily "Free" Downvote Power - which has 20% of the upvoting Mana. We can use the following Javascript/NodeJs function to calculate the downvote power.
We can access the "last" seen downvote mana and the timestamp in the getAccounts API - then we need to calculate the mana restored since the timestamp.
And by using async/await, you can await getting the downvote power in a function that is marked async.
function getDownvotePower(id) {
return new Promise((resolve, reject) => {
steem.api.getAccounts([id], function(err, response) {
if (err) reject(err);
const current_mana = response[0].voting_manabar.current_mana;
const downvote_mana = response[0].downvote_manabar.current_mana;
const downvote_last_update_time = response[0].downvote_manabar.last_update_time;
const downvote_per = downvote_mana / (current_mana / (response[0].voting_power / 100) / 4);
const secondsago = (new Date - new Date(downvote_last_update_time * 1000)) / 1000;
let vpow = downvote_per * 100 + (10000 * secondsago / 432000);
resolve(Math.min(vpow / 100, 100).toFixed(2));
});
});
}
// Sample Usage
(async function() {
const val = await getDownvotePower('justyy');
log(val);
})();
Run the code at SteemJS Editor.
Reposted to Blog
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^
NEW! Following my Trail (Upvote or/and Downvote)
Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com
My contributions
- Steem Blockchain Tools
- Computing & Technology
- Download Youtube Video
- Find Cheap & Bargin VPS: VPS Database
- Online Software and Tools
- Online File/Video Merger
Delegation Service
Support me
If you like my work, please:
- Buy Me a Coffee, Thanks!
- Become my Sponsor, Thanks!
- Voting for me:
https://steemit.com/~witnesses type in justyy and click VOTE
- Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
- Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
- Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses
Hii sir @justyy
I've chosen you as a proxy, and delegated my 300 steem
Thank you!