Transforming Vests Into SP (Delegation) with APIs.

in hive-151113 •  last year 

Yellow Bright Business Idea Tutorial Youtube Thumbnail_20240215_135519_0000~2.png

Hello Steemians,

In the world of Steem blockchain, understanding the intricacies of Steem Power and vesting is crucial for users looking to maximize their influence and rewards. Steem Power represents a user assets that are stake on steemit. Basically vesting is the process by which Steem Power is acquired and it can be complex to grasp. In this post, we will explore how to calculate Steem Power from vest using two key APIs and calculate the delegation amount that is given to an account.

When users delegate Steem Power to another account. they essentially transfer their voting power to that account. This delegations are measured in vesting shares that represent the Steem Power. It is not immediately tradable. To calculate vesting shares to Steem Power, one must consider the current Steem-to-vest ratio, shared below API's are needed.

Data Fetching APIs

  • Steemworld Delegations API: This API provides information about incoming delegations to a specified account.
  • Steemyy Vests API: This API offers data regarding the current Steem-to-vest ratio, essential for converting vesting shares into Steem Power.
Const username2 = 'beautycreativity' ;

var api1 = `https://sds.steemworld.org/delegations_api/getIncomingDelegations/${username2}`;

var api2 = `https://steemyy.com/api/steemit/vests/?cached`;

let data;
let data1;

const fetchApi1 = fetch(api1)
  .then(response => response.json())
  .then(apiData => {
    data = apiData.result.rows;
  })
  .catch(error => {
    console.error('Error fetching data from api1:', error);
  });

const fetchApi2 = fetch(api2)
  .then(response => response.json())
  .then(apiData2 => {
    data1 = apiData2['steem_per_mvests'];
  })
  .catch(error => {
    console.error('Error fetching data from api2:', error);
  });


Promise.all([fetchApi1, fetchApi2])
  .then(() => {
    function convertTimestampToReadableDate(timestamp) {
      const date = new Date(timestamp * 1000); 
      const formattedDate = date.toUTCString();
      return formattedDate;
    }

    function convertVestIntoSteemPower(Vest) {
      const sp = ((Vest * data1) / 1e6) * 1000;
      return sp;
    }

  const convertedArray = data.map((innerArray, index) => {
  const timestamp = innerArray[0];
  const Vest = innerArray[3];
  const readableDate = convertTimestampToReadableDate(timestamp);
  const SteemPower = convertVestIntoSteemPower(Vest);
  return [index + 1, readableDate, innerArray[1], innerArray[2], SteemPower];
});
    
    const markdownTable = `
| No | Delegator | Amount (SP) | Date & Time |
|----|-----------|-------------|-------------|
${convertedArray.map(row => `|${row[0]}|@${row[2]}|${row[4].toFixed(2)}|${row[1]}|`).join('\n')}
    `;

    console.log(markdownTable);
    const sumSP = convertedArray.reduce((sum, row) => sum + row[4], 0);
    const countrows = convertedArray.length;
    
    }
     


In the above code, Delegated amount of every delegator will convert into delegated steem power from vests and store in the form of table markdown style in markdown table variable.


Please cast witness vote to bangla.Witness or set proxy to rme.

_
Vote bangla.witness as witness
Set Proxy rme as proxy

Special Thanks.

Cc: @rme
Cc: @hungry-griffin
Cc: @steemcurator01
Cc: @steemchiller
Cc: @pennsif

Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram

🆃🅷🅰️🅽🅺 🆈🅾️🆄

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.