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.
1 2 3 4 5 6 7 8 9 10 11 12 | 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 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <?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; } } |
<?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:
1 | curl -X GET -s "https://anothervps.com/api/steemit/vests/" |
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) —
loading...
Last Post: The Javascript's Memorization Function to Speed Up Recursion (Dynamic Programming)
Next Post: HHKB (Happy Hacking Keyboard) Review and the Key Combinations