Algorithms, Blockchain and Cloud

How to Convert VESTS to STEEM and vice versa?


On STEEM blockchain, the rewards are distributed in the unit of VESTS which can be converted to more human-readable unit of the SP – The Steem Power. The STEEM can be transferred from Steem accounts, the minimal amount of STEEM is 0.001.

Convert Vests to STEEM and Vice versa using Steem/Python

With Steem/Python library, through the steem.converter object, we can get the value of steem_per_mvests.

from steem.converter import Converter
from steem import Steem

def steem_to_vests(sp):
  steem = Steem()
  converter = Converter(steemd_instance = steem)
  return sp * 1e6 / converter.steem_per_mvests()

def vests_to_steem(vests):
  steem = Steem()
  converter = Converter(steemd_instance = steem)
  return converter.steem_per_mvests() * 1e6   

1e6 / steem_per_mvests() is the number of VESTS that is equal to 1 Steem Power. steem_per_mvests() (How many steem per million vests) can be also obtained via https://api.steemit.com at endpoint database_api.get_dynamic_global_properties.

PHP Function to Convert Vests to STEEM and Vice versa

As mentioned above, the conversion values can be queried via the https://api.steemit.com – through database_api.get_dynamic_global_properties. The PHP function is provided as belows:

<?php
function steem_per_mvests() {
    $url = 'https://api.steemit.com';
    $data = '{"jsonrpc":"2.0", "method":"database_api.get_dynamic_global_properties", "id":1}';
    $options = array(
      'http' =>
        array(
          'header' => "Content-Type: application/json\r\n".
                      "Content-Length: ".strlen($data)."\r\n".
                      "User-Agent:SteemYY.com/1.0\r\n",
          'method'  => 'POST',
          'content' => $data,
        )
    );
    $context  = stream_context_create($options);
    try {
        $result = file_get_contents($url, false, $context);
        $r = json_decode($result, true);
        $result = $r['result'];
    } catch (\Exception $e) {
        return false;
    }
    return $result['total_vesting_fund_steem']['amount'] / ($result['total_vesting_shares']['amount'] / 1e6);
}

function vests_to_sp($vests) {
    $steem_per_mvests = steem_per_mvests();
    if ($steem_per_mvests) {
        return $vests / 1e3 * $steem_per_mvests;
    } else {
        return false;
    }
} 

function sp_to_vests($sp) {
    $steem_per_mvests = steem_per_mvests();
    if ($steem_per_mvests) {
        return $sp * 1e6 / $steem_per_mvests;
    } else {
        return false;
    }
}

Free API of vests-to-steem and steem-to-vests

The above conversion has been implemented as a API that can be used freely subject to fair use policy.

For example:

curl -X GET -s "https://anothervps.com/api/steemit/vests/"

It will return JSON-encoded data:

{"sp_to_vests":2017.0314963280616,
"vests_to_sp":0.0004957780787362352,
"steem_per_mvests":0.4957780787362352}

The API server can be replaced with:

  • West USA: steakovercooked.com
  • East USA: helloacm.com
  • London, UK: uploadbeta.com
  • Tokyo, Japan: happyukgo.com

–EOF (The Ultimate Computing & Technology Blog) —

499 words
Last Post: The Javascript's Memorization Function to Speed Up Recursion (Dynamic Programming)
Next Post: HHKB (Happy Hacking Keyboard) Review and the Key Combinations

The Permanent URL is: How to Convert VESTS to STEEM and vice versa? (AMP Version)

Exit mobile version