create account

Hivejs: How to delegtae hivepower - Wie delegiert man Hivepower? # 15 by hive-coding

View this thread on: hive.blogpeakd.comecency.com
· @hive-coding · (edited)
$2.12
Hivejs: How to delegtae hivepower - Wie delegiert man Hivepower? # 15
## DE (EN below)
![](https://images.ecency.com/DQmNV9sDUp4Aa774yQNfipd6zwsEuTBXSouKkN2U7LYmBzg/grafik.png)

In meinen Beiträgen [#12](https://ecency.com/hive/@hive-coding/hivejs-how-to-get-delegations) und  [#13](https://ecency.com/hive-169321/@hive-coding/hivesql-how-to-get-delegations) habe ich erklärt, wie man mit HiveJS bzw. HiveSQL Delegationen auslesen kann. 

In diesem Beitrag möchte ich erklären, wie man mit HiveJS Hivepower delegiert an andere Nutzer.

![](https://images.ecency.com/DQmez1SbH4rrQFWQPjx5Pwvs2euryA4wJHWsj8428UFoNyk/grafik.png)

Dafür nutzen wir die Funktion [hive.broadcast.delegateVestingShares](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#delegate-vesting-shares). Der Funktion erwartet 4 Parameter:

* **wif** der private Aktiv-Schlüssel des Nutzers der delegiert
* **delegator** der Nutzer, der HivePower delegiert
* **delegatee** der Nutzer, der HivePower delegiert bekommt
* **vesting_shares** HivePower in Vests

Um die Hivepower in Vests anzugeben, müssen wir die Hive in Vests umrechnen und benötigen dafür total_vesting_fund_hive und total_vesting_shares die wir mit der Funktion  [hive.broadcast.getDynamicGlobalProperties](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties) erhalten.

Die vesting_shares ergeben sich durch folgende Rechnung:
vesting_shares=total_vesting_shares* HivePower/total_vesting_fund_hive;

Wie ich im vorherigen Beitrag erklärt habe, gibt es die Funktion [hive.formatter.vestToHive](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties), leider gibt es keine Funktion hiveToVest.

![](https://images.ecency.com/DQma1kGHvmExGQLAKWCQemNgfHrMvzvSe1UVcJuwac55Ggi/grafik.png)

Daher müssen wir die Berechnung selber durchführen und darauf achten, dass wir Hive bzw. Vests erst entfernen, das Ergebnis dann mit 6 Stellen angeben und VESTS anfügen.

```javascript
var vesting_shares=parseFloat(total_vesting_shares.split(" ")[0]) *parseFloat($("#hive").val()) /parseFloat(total_vesting_fund_hive.split(" ")[0]);
   vesting_shares=vesting_shares.toFixed(6)+" VESTS";
```

Dabei gilt immer die zuletzt übertragene Menge als delegiert. Beachtet, wenn Ihr einen kleineren Betrag delegiert als zuvor, so ist die Differenz nicht sofort wieder verfügbar. Es dauert 7 Tage, bis diese euch wieder zur Verfügung steht.

Habt ihr einem Nutzer 100 Hive delegiert und möchtet es auf 110 erhöhen dürft ihr nicht weitere 10 Hive delegieren, denn dann delegiert ihr nur 10 Hive und 90 Hive werden euch innerhalb von 7 Tagen wieder zur Verfügung stehen. Du musst somit 110 hive delegieren.

Dementsprechend beendet man eine Delegation in dem man "0.000000 VESTS" delegiert.

Das Beispiel findet ihr [hier](https://jsfiddle.net/hive_coding/3Lf96abj/), nutzt diesen nur Lokal, gebt nie euren privaten Aktiv-Schlüssel auf jsfiddle ein!

Wer Fragen hat, kann gern ein Kommentar da lassen. Am besten @mein-senf-dazu erwähnen, damit ich es mitbekomme.

## EN
![](https://images.ecency.com/DQmNV9sDUp4Aa774yQNfipd6zwsEuTBXSouKkN2U7LYmBzg/grafik.png)

In my posts [#12](https://ecency.com/hive/@hive-coding/hivejs-how-to-get-delegations) and [#13](https://ecency.com/hive-169321/@hive-coding/hivesql-how-to-get-delegations) I explained how to read delegations with HiveJS and HiveSQL respectively. 

In this post I want to explain how to delegate Hivepower to other users with HiveJS.

![](https://images.ecency.com/DQmez1SbH4rrQFWQPjx5Pwvs2euryA4wJHWsj8428UFoNyk/grafik.png)

For this we use the function [hive.broadcast.delegateVestingShares](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#delegate-vesting-shares). The function expects 4 parameters:

* **wif** the private active key of the user who delegates.
**delegator** the user who delegates HivePower
**delegatee** the user who gets HivePower delegated
* **investing_shares** HivePower in Vests.

To specify the hivepower in vests, we need to convert the hive to vests and for that we need total_vesting_fund_hive and total_vesting_shares which we get with the function [hive.broadcast.getDynamicGlobalProperties](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties).

The vesting_shares are obtained by the following calculation:
vesting_shares=total_investing_shares* HivePower/total_investing_fund_hive;

As I explained in the previous post, there is a function [hive.formatter.vestToHive](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties), unfortunately there is no function hiveToVest.

![](https://images.ecency.com/DQma1kGHvmExGQLAKWCQemNgfHrMvzvSe1UVcJuwac55Ggi/grafik.png)

So we have to do the calculation ourselves, making sure to remove hive or vests first, then specify the result with 6 digits and append VESTS.

```javascript
var vesting_shares=parseFloat(total_vesting_shares.split(" ")[0]) *parseFloat($("#hive").val()) /parseFloat(total_vesting_fund_hive.split(" ")[0]);
   vesting_shares=vesting_shares.toFixed(6)+" VESTS";
```

In this case, the last amount transferred is always considered delegated. Note that if you delegate a smaller amount than before, the difference is not immediately available again. It takes 7 days until it is available again.

If you have delegated 100 hive to a user and you want to increase it to 110 you must not delegate another 10 hive, because then you delegate only 10 hive and 90 hive will be available to you again within 7 days. You have to delegate 110 hive.

Accordingly, you end a delegation by delegating "0.000000 VESTS".

You can find the example [here](https://jsfiddle.net/hive_coding/3Lf96abj/), use this only locally, never enter your private active key on jsfiddle!

If you have any questions, feel free to leave a comment. It's best to mention @mein-senf-dazu, so I can see it.

Translated with www.DeepL.com/Translator (free version)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 21 others
👎  
properties (23)
authorhive-coding
permlinkhivejs-how-to-delegtae-hivepower
categoryhive-169321
json_metadata{"app":"ecency/3.0.30-vision","description":"","format":"markdown+html","image":["https://images.ecency.com/DQmNV9sDUp4Aa774yQNfipd6zwsEuTBXSouKkN2U7LYmBzg/grafik.png","https://images.ecency.com/DQmez1SbH4rrQFWQPjx5Pwvs2euryA4wJHWsj8428UFoNyk/grafik.png","https://images.ecency.com/DQma1kGHvmExGQLAKWCQemNgfHrMvzvSe1UVcJuwac55Ggi/grafik.png","https://images.ecency.com/DQmNV9sDUp4Aa774yQNfipd6zwsEuTBXSouKkN2U7LYmBzg/grafik.png","https://images.ecency.com/DQmez1SbH4rrQFWQPjx5Pwvs2euryA4wJHWsj8428UFoNyk/grafik.png","https://images.ecency.com/DQma1kGHvmExGQLAKWCQemNgfHrMvzvSe1UVcJuwac55Ggi/grafik.png"],"links":["https://ecency.com/hive/@hive-coding/hivejs-how-to-get-delegations","https://ecency.com/hive-169321/@hive-coding/hivesql-how-to-get-delegations","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#delegate-vesting-shares","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties","https://jsfiddle.net/hive_coding/3Lf96abj/","https://ecency.com/hive/@hive-coding/hivejs-how-to-get-delegations","https://ecency.com/hive-169321/@hive-coding/hivesql-how-to-get-delegations","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#delegate-vesting-shares","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#get-dynamic-global-properties"],"tags":["hive-169321"],"users":["mein-senf-dazu","mein-senf-dazu"]}
created2022-12-17 15:05:39
last_update2022-12-17 15:10:24
depth0
children2
last_payout2022-12-24 15:05:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value2.123 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,853
author_reputation8,653,483,468,469
root_title"Hivejs: How to delegtae hivepower - Wie delegiert man Hivepower? # 15"
beneficiaries
0.
accountmein-senf-dazu
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id119,183,853
net_rshares10,760,506,061,662
author_curate_reward""
vote details (86)
@ecency ·
**Yay!** 🤗<br>Your content has been **boosted with Ecency Points**, by @mein-senf-dazu. <br>Use Ecency daily to boost your growth on platform! <br><br><b>Support Ecency</b><br>[Vote for new Proposal](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B245%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
properties (22)
authorecency
permlinkre-20221217t211351220z
categoryhive-169321
json_metadata{"tags":["ecency"],"app":"ecency/3.0.20-welcome","format":"markdown+html"}
created2022-12-17 21:13:51
last_update2022-12-17 21:13:51
depth1
children0
last_payout2022-12-24 21:13:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length384
author_reputation630,689,395,572,402
root_title"Hivejs: How to delegtae hivepower - Wie delegiert man Hivepower? # 15"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,190,757
net_rshares0
@p1k4ppa10 ·
I was not familiar with this process; look around and read posts on Hive you always learn new things heh heh! Thanks for sharing!
properties (22)
authorp1k4ppa10
permlinkre-hive-coding-20221223t182039420z
categoryhive-169321
json_metadata{"tags":["hive-169321"],"app":"ecency/3.0.30-vision","format":"markdown+html"}
created2022-12-23 17:20:39
last_update2022-12-23 17:20:39
depth1
children0
last_payout2022-12-30 17:20:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length129
author_reputation263,648,445,828,342
root_title"Hivejs: How to delegtae hivepower - Wie delegiert man Hivepower? # 15"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,332,822
net_rshares0