<center>https://cdn.steemitimages.com/DQmUFn39XJ5bVh4hg9y1GiFBQH8ikfBqzMLmViUMQafmQMG/image.png</center> Earlier today I was trying to programmatically delegate to one of my accounts with the following (correct) code: ```const dsteem = require('dsteem'); const client = new dsteem.Client('https://api.steemit.com'); const delegate = async (config) => { const { delegation, privateKey: privateActiveKey, delegator, delegatee, } = config; const privateKey = dsteem.PrivateKey.fromString(privateActiveKey); const op = [ 'delegate_vesting_shares', { delegator, delegatee, vesting_shares: delegation, }, ]; client.broadcast.sendOperations([op], privateKey).then( result => console.log('Delegation done.', JSON.stringify(result)), console.error, ); }; const config = { delegatee: 'bot-test', delegator: 'marcocasario', privateKey: '51111111111111111111111111111111111111111111111RlFx', // private active key delegation: '29456.000000 VESTS', // Around 15 SP }; delegate(config); ``` <br> Initially though I was passing in as input STEEM instead of VEST so the script was erroring out. After reading a bit around I found out how to easily convert one into the other. Here is the JS code: <br> ``` const cache = { totVestShares: null, totSteem: null, }; const getProps = () => new Promise((res) => { fetch('https://api.steemit.com', { method: 'POST', cache: 'no-cache', credentials: 'omit', headers: { 'Content-Type': 'application/json', }, redirect: 'follow', referrerPolicy: 'no-referrer', body: JSON.stringify({ jsonrpc: '2.0', method: 'condenser_api.get_dynamic_global_properties', params: [], id: 1, }), }).then(res => res.json()).then((data) => {console.log(data);res(data.result)}); }); // Usage: steemToVest('15 STEEM'); >> '29456.000000 VESTS' const steemToVest = async (steem) => { if (!cache.totSteem) { const { total_vesting_shares, total_vesting_fund_steem } = await getProps(); cache.totVestShares = +total_vesting_shares.split(' ')[0]; cache.totSteem = +total_vesting_fund_steem.split(' ')[0]; } const steemAmount = +steem.split(' ')[0]; const vests = steemAmount * cache.totVestShares / cache.totSteem; // Always 6 decimals and rounded const roundedVests = (Math.round(vests * 1000000 + Number.EPSILON) / 1000000).toFixed(6); console.log(`${steemAmount} STEEM is ${roundedVests} VESTS.`); return roundedVests; }; // Usage: vestsToSteem('29456.61988576255 VESTS'); >> '15.000 STEEM' const vestsToSteem = async (vests) => { if (!cache.totSteem) { const { total_vesting_shares, total_vesting_fund_steem } = await getProps(); cache.totVestShares = +total_vesting_shares.split(' ')[0]; cache.totSteem = +total_vesting_fund_steem.split(' ')[0]; } const vestsAmount = +vests.split(' ')[0]; const steem = vestsAmount * cache.totSteem / cache.totVestShares; const roundedSteem = (Math.round(steem * 1000 + Number.EPSILON) / 1000).toFixed(3); console.log(`${vestsAmount} VESTS is ${roundedSteem} STEEM.`); // Always 3 decimals and rounded return roundedSteem; }; ``` <div class="phishy pull-left"> <h4>USAGE:</h4> This is even easier than <a href="https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-steemit-accounts-information-programmatically">retrieving balances of a list of Steemit accounts</a> or <a href="https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically">calculate an account's RC programmatically</a> as there is no need to import SteemJs or SteemdJs for the VEST <=> STEEM conversion. The script simply uses a cross domain http requests. This means that you can try this simple script in any webpage. <b>Step by step instructions:</b> <b>STEP 1</b> Open your favorite browser on any site (I strongly recommend using [Brave browser](https://brave.com/myc159)) and open the DevTools (Ctrl + Shift + J on Linux/Windows and Cmd + Opt + J on Mac). <b>STEP 2</b> Copy and paste my script above in the Console. <b>STEP 3</b> Press enter and there you go! You can now execute the 2 commands to convert between STEEM and VESTS. Enjoy!! =] NOTE: As usual, this script is completely safe as it does not require any sort of keys to function and can be executed in any webpage!
author | gaottantacinque | ||||||
---|---|---|---|---|---|---|---|
permlink | here-is-how-you-can-easily-delegate-sp-and-convert-between-vest-and-steem-programmatically | ||||||
category | steemit | ||||||
json_metadata | {"tags":["stem","blockchain","neoxian","palnet","programming","javascript","art"],"image":["https://cdn.steemitimages.com/DQmUFn39XJ5bVh4hg9y1GiFBQH8ikfBqzMLmViUMQafmQMG/image.png"],"links":["https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-steemit-accounts-information-programmatically","https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically","https://brave.com/myc159"],"app":"steemit/0.1","format":"markdown"} | ||||||
created | 2020-01-31 07:44:51 | ||||||
last_update | 2020-01-31 07:59:21 | ||||||
depth | 0 | ||||||
children | 4 | ||||||
last_payout | 2020-02-07 07:44:51 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.341 HBD | ||||||
curator_payout_value | 0.361 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 4,533 | ||||||
author_reputation | 13,463,378,539,470 | ||||||
root_title | "Here is how you can easily delegate SP and convert between VEST and STEEM programmatically" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 94,951,992 | ||||||
net_rshares | 3,666,493,540,343 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
gerber | 0 | 322,957,005,947 | 6% | ||
daan | 0 | 185,470,306,246 | 3% | ||
exyle | 0 | 339,787,760,085 | 5% | ||
bridgetbunchy | 0 | 59,965,929,069 | 25% | ||
svetlanaaa | 0 | 6,343,039,504 | 99% | ||
cryptomancer | 0 | 16,229,395,308 | 30% | ||
ebargains | 0 | 2,382,272,468 | 5% | ||
okean123 | 0 | 4,578,977,018 | 10% | ||
slh84 | 0 | 39,107,792 | 50% | ||
frankk | 0 | 12,785,204,500 | 35% | ||
eliel | 0 | 8,647,267,921 | 5% | ||
improv | 0 | 1,235,392,705 | 0.75% | ||
anacristinasilva | 0 | 4,052,397,356 | 5% | ||
techken | 0 | 7,489,101 | 0.35% | ||
furious-one | 0 | 12,016,178,105 | 25% | ||
edkarnie | 0 | 40,764,115,578 | 10% | ||
raili | 0 | 1,953,122,747 | 30% | ||
stinawog | 0 | 630,935,827 | 5% | ||
accelerator | 0 | 18,720,977,787 | 1% | ||
osm0sis | 0 | 3,892,661,024 | 5% | ||
espoem | 0 | 11,614,933,803 | 5% | ||
blockbrothers | 0 | 80,476,336,473 | 2.5% | ||
imisstheoldkanye | 0 | 2,284,208,545 | 1% | ||
potplucker | 0 | 1,631,521,450 | 7% | ||
fredkese | 0 | 3,489,247,901 | 100% | ||
mytechtrail | 0 | 44,565,978,981 | 25% | ||
cryptodecript | 0 | 765,592,255 | 10% | ||
funnyco | 0 | 59,996,802 | 10% | ||
mattiarinaldoni | 0 | 178,695,845 | 5% | ||
flysky | 0 | 267,476,654,168 | 5% | ||
curx | 0 | 10,893,612,636 | 5% | ||
piotrgrafik | 0 | 15,047,980,188 | 5% | ||
investprosper | 0 | 987,743,105 | 2.91% | ||
cadawg | 0 | 18,781,009,880 | 4.2% | ||
raise-me-up | 0 | 0 | 0.01% | ||
florenceboens | 0 | 866,163,350 | 10% | ||
condeas | 0 | 70,151,155,917 | 50% | ||
thecontractor | 0 | 4,959,917,814 | 15% | ||
mindtrap | 0 | 21,341,625,165 | 2% | ||
clm | 0 | 856,046,761 | 5% | ||
bestboom | 0 | 46,973,435,586 | 6% | ||
tonimontana | 0 | 59,746,507 | 3.09% | ||
wirednkod | 0 | 65,980,461 | 25% | ||
arcanebinder | 0 | 65,948,195 | 100% | ||
steem.services | 0 | 209,406,243,026 | 3.5% | ||
eii | 0 | 4,738,500,876 | 10% | ||
pladozero | 0 | 44,881,722,485 | 10% | ||
nateaguila | 0 | 209,614,845,479 | 8% | ||
enforcer48 | 0 | 56,003,923,958 | 15% | ||
sergino | 0 | 3,296,725,964 | 10% | ||
steemitsupporter | 0 | 6,127,906,040 | 13% | ||
sbi5 | 0 | 141,539,662,818 | 10.49% | ||
gaottantacinque | 0 | 2,546,857,427 | 100% | ||
kafupraise | 0 | 92,955,678 | 35% | ||
gasaeightyfive | 0 | 3,397,687,177 | 100% | ||
dlike | 0 | 185,083,247,081 | 2.6% | ||
skylinebuds | 0 | 1,005,683,667 | 2% | ||
triptolemus | 0 | 23,783,573,800 | 6% | ||
marcocasario | 0 | 13,299,913,922 | 50% | ||
laissez-faire | 0 | 68,783,472 | 100% | ||
aicurator | 0 | 7,792,307,276 | 5% | ||
merlin7 | 0 | 68,664,330,903 | 6% | ||
linuxbot | 0 | 6,586,497,236 | 40% | ||
ambercookie | 0 | 61,771,782 | 72% | ||
primeradue | 0 | 5,921,106,399 | 6% | ||
permaculturedude | 0 | 1,136,481,516 | 3% | ||
the.curator | 0 | 1,754,064,246 | 5% | ||
mohaaking | 0 | 53,211,206 | 50% | ||
fsm-liquid | 0 | 13,057,652,650 | 5% | ||
budwizard | 0 | 0 | 1% | ||
sharingiscaring1 | 0 | 35,965,700,113 | 100% | ||
triplea.bot | 0 | 2,234,468,665 | 5% | ||
steem.leo | 0 | 173,670,922,094 | 5.7% | ||
leo.voter | 0 | 715,658,916,826 | 5.82% | ||
freddio.sport | 0 | 54,748,843,956 | 15% | ||
parbati | 0 | 582,330,660 | 100% | ||
sonami | 0 | 598,717,620 | 100% | ||
mapxv | 0 | 6,982,068,724 | 0.8% | ||
sbi-tokens | 0 | 1,120,707 | 0.82% | ||
joshuafootball | 0 | 1,991,652,448 | 100% | ||
leo.syndication | 0 | 2,796,861,243 | 6% | ||
curation.stem | 0 | 0 | 75% | ||
wrichardsonjr | 0 | 598,509,700 | 100% | ||
mk-stem-token | 0 | 346,781,065 | 10% | ||
maxuvb | 0 | 610,912,842 | 1% | ||
maxuvc | 0 | 614,415,581 | 1% | ||
maxuve | 0 | 3,567,668,026 | 0.8% | ||
smaldl | 0 | 5,545,225,368 | 100% | ||
stemd | 0 | 176,402,207 | 100% | ||
listentous | 0 | 602,887,355 | 100% | ||
tonimontana.neo | 0 | 28,691,299 | 2% | ||
santoshkc | 0 | 582,171,526 | 100% | ||
yggdrasil.laguna | 0 | 365,533,670 | 70% | ||
creativetru.neox | 0 | 69,930,879 | 6% | ||
kst19 | 0 | 582,336,669 | 100% | ||
churchofgod | 0 | 468,116,073 | 1% | ||
topadultcurator | 0 | 189,808,957 | 10% | ||
tonystarkalive | 0 | 28,783,138 | 2% | ||
neoxvoter | 0 | 82,443,757 | 1.5% | ||
frimold | 0 | -9,138,253 | -10% | ||
ssbank | 0 | 0 | 10% | ||
evrista | 0 | -9,087,950 | -10% | ||
bilpcoinpower | 0 | 258,806,656 | 10% | ||
tansm11 | 0 | 592,014,762 | 100% |
<div class='pull-right'>https://cdn.steemitimages.com/DQmaHThyECGhEx8tSfHZbiMFRNYjJ35K92cDgiJjkzBUaJo/One%20sip%20of%20BEER%20for%20you.gif<p><sup><a href='https://steem-engine.com/?p=market&t=BEER'>View or trade </a> <code>BEER</code>.</sup></p></div><center><br> <p> Hey @gaottantacinque, here is a little bit of <code>BEER</code> from @eii for you. Enjoy it!</p> <p>Learn how to <a href='https://steemit.com/beer/@beerlover/what-is-proof-of-stake-with-beer'>earn FREE BEER each day </a> by staking.</p> </center><div></div>
author | beerlover |
---|---|
permlink | re-here-is-how-you-can-easily-delegate-sp-and-convert-between-vest-and-steem-programmatically-20200131t092829z |
category | steemit |
json_metadata | "{"app": "beem/0.21.1"}" |
created | 2020-01-31 09:28:33 |
last_update | 2020-01-31 09:28:33 |
depth | 1 |
children | 0 |
last_payout | 2020-02-07 09:28:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 526 |
author_reputation | 25,764,855,350,472 |
root_title | "Here is how you can easily delegate SP and convert between VEST and STEEM programmatically" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 94,953,854 |
net_rshares | 0 |
!COFFEEA !shop $trdo !BEER
author | eii |
---|---|
permlink | re-gaottantacinque-q4ysz1 |
category | steemit |
json_metadata | {"tags":["steemit"],"app":"steempeak/2.2.8"} |
created | 2020-01-31 09:28:15 |
last_update | 2020-01-31 09:28:15 |
depth | 1 |
children | 1 |
last_payout | 2020-02-07 09:28:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 26 |
author_reputation | 181,092,811,369,851 |
root_title | "Here is how you can easily delegate SP and convert between VEST and STEEM programmatically" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 94,953,845 |
net_rshares | 0 |
Congratulations @eii, you successfuly trended the post shared by @gaottantacinque! @gaottantacinque will receive <b>0.04182638</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) & @eii will get <b>0.02788425</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation in 3 Days from Post Created Date! <b>"Call [TRDO](https://steem-engine.com/?p=history&t=TRDO), Your Comment Worth Something!"</b> --- <sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO) Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
author | trendotoken |
---|---|
permlink | re-eii-re-gaottantacinque-q4ysz1-20200131t092824364z |
category | steemit |
json_metadata | {"tags":["comments-scot","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"} |
created | 2020-01-31 09:28:24 |
last_update | 2020-01-31 09:28:24 |
depth | 2 |
children | 0 |
last_payout | 2020-02-07 09:28:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 622 |
author_reputation | 5,546,209,053,433 |
root_title | "Here is how you can easily delegate SP and convert between VEST and STEEM programmatically" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 94,953,849 |
net_rshares | 0 |
Congratulations @gaottantacinque, your post successfully recieved <b>0.04182638</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) from below listed TRENDO callers:<br> > <sup>@eii earned : **0.02788425** [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation</sup> --- <sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO) Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
author | trendotoken |
---|---|
permlink | re-gaottantacinque-here-is-how-you-can-easily-delegate-sp-and-convert-between-vest-and-steem-programmatically-20200203t075115286z |
category | steemit |
json_metadata | {"tags":["trdo","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"} |
created | 2020-02-03 07:51:21 |
last_update | 2020-02-03 07:51:21 |
depth | 1 |
children | 0 |
last_payout | 2020-02-10 07:51:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 492 |
author_reputation | 5,546,209,053,433 |
root_title | "Here is how you can easily delegate SP and convert between VEST and STEEM programmatically" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 95,047,439 |
net_rshares | 0 |