Compute the Account Voting Power (Mana) for Accounts on Steem Blockchain using Javascript/NodeJs Function

in #witness-category4 years ago (edited)

Previously, we learn how to use Javascript/NodeJs function to compute the real downvote mana/power for accounts on steem blockchain via the steem.api.getAccounts API. Today, we are going to compute the upvote mana/power instead.

Computing the upvote mana/power for accounts on Steem Blockchain is a bit easier than the downvote power. We still need to apply the restored mana since users' last upvoting activity.

function getUpvotePower(id) {
    return new Promise((resolve, reject) => {
        steem.api.getAccounts([id], function(err, response) {
            if (err) reject(err);
            const secondsago = (new Date - new Date(response[0].last_vote_time + "Z")) / 1000;
            let vpow = response[0].voting_power + (10000 * secondsago / 432000);
            resolve(Math.min(vpow / 100, 100).toFixed(2));
        });          
    });
}

(async function() {
    const val = await getUpvotePower('justyy');
    log(val);
})();

Run this code on Steem JS Editor.

Similarly, the function returns a promise so that you can use await in an async function.

To compute the downvote power/mana: Javascript (NodeJS) Function to Get the Downvote Power of Account on Steem Blockchain

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

Delegation Service

  1. Voting Algorithm Updated to Favor those High Delegations!
  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. 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

Sort:  

please support me @justyy

[WhereIn Android] (http://www.wherein.io)

hello @justyy
i've noticed that you have decreased the amoun of vote from 0.57 to 0.37...may i ask why?

more text more weight, and if your delegated SP is almost all of you SP, you will get more.

Hmmmm... that certainly sounds interesting... maybe I'll try it and delegate you about 500sp in the next few days and see how far that "more" can go.

Thank you for your reply and the information you provided... much appreciated.

Respect @justyy

Thank for information, i have follow u to set my proxy...
And i have delegation steem power 50SP....
Glad to work with u, greetings....

Screenshot_20210507-235946.png

Screenshot_20210507-235607.png

Coin Marketplace

STEEM 0.22
TRX 0.20
JST 0.034
BTC 92868.99
ETH 3121.42
USDT 1.00
SBD 3.14