create account

Hivejs: How to vote - Wie man ein Vote abgibt #4 by hive-coding

View this thread on: hive.blogpeakd.comecency.com
· @hive-coding ·
$33.12
Hivejs: How to vote - Wie man ein Vote abgibt #4
# EN

## How to cast a vote
So far, in the first three parts of my series on Hivejs, we've only queried data from the blockchain. Today, we're going to talk about interacting with the blockchain. We want to cast a vote on a post. To do that, let's take a look at the [broadcast functions](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast), to be more specific, the [hive.broadcast.vote](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#vote) function.

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

As you can see, this expects 5 parameters:

* **wif** - Your private posting key, from the voter account.
* **voter** - The account you want to vote with
* **author** - Who you want to give a vote to
**permlink** - which post/comment you want to give a vote to
* **weight** - The weight of your vote, 1-10000, 10000 equals 100%.
Only if you have a lot of HivePower it makes sense to give a small vote. If you use a negative number between -1 and -10000, you give a downvote, if you use 0, a previous vote/downvote will be taken back.

## Attention/Important
**Although I link an example on jsfiddel here at the end, never use your posting key on any website! Use the script only on your PC for tests. If someone gets your posting key, he can do a lot with it, including posting and voting!**

## pass weight as number
![](https://images.ecency.com/DQmNgjuNYQ5oSkV5t9Jy1nrRaoEEsFhNbwJKwtdfZ32WTRA/grafik.png)
If you forget to pass weight as a number, you will see the above in the console.

## Vote successfully submitted
![](https://images.ecency.com/DQmZ5d29hPDw4QMqcV1A7b61g7CFuQCU8PrqSfriRL4NBZa/grafik.png)

This is what it looks like when the vote was successfully submitted to the blockchain, but be careful, because you can also give a vote to old posts, but this doesn't make sense, because the author only gets a reward for votes within 7 days.

That this is possible, you can see here on the screenshot:
![](https://images.ecency.com/DQmdmUftrqjWnY2x9MAq5VVuP6sZ8fpL5DhRZKWFB3yAMZ8/grafik.png)

The last vote before mine is already 8 days old. The post is therefore already older than 7 days old. As far as I can see, you don't lose any voting power if you do it. 

## Double Vote
![](https://images.ecency.com/DQmcXM9cXepHZdzwHV4Zhv7Mh2dUt8UbyMf6hNDMpcnhdjj/grafik.png)
If you have already voted with the same weighting, you will get the above error message.

## incorrect permlink/author
![](https://images.ecency.com/DQmQ5E6dLgqgAZsSTemnbhNJbB6mJExtq9LmGubDfvq4TdD/grafik.png)
This is what the error message looks like if you use a permlink that does not exist with the author, or even if the author does not exist at all.

[Here is](https://jsfiddle.net/hive_coding/6d4n807r) the code on jsfiddle. **Again the warning, don't use your key there!

I hope it was understandable. If you have questions, then write a comment and best you mention my account @mein-senf-dazu, then I get that sooner.

Translated with www.DeepL.com/Translator (free version)

# DE

## Wie man ein Vote abgibt
In den ersten drei Teilen meiner Reihe zu Hivejs haben wir bisher nur Daten von der Blockchain abgefragt. Heute geht es darum, mit der Blockchain zu interagieren. Wir wollen ein Vote auf einen Beitrag abgeben. Dafür schauen wir uns die [Broadcast-Funktionen](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast) einmal an, um genauer zu sein, die Funktion [hive.broadcast.vote](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#vote).

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

Wie ihr sehen könnt, erwartet diese 5 Parameter:

* **wif** - Dein Privater Postingschlüssel, zum Voter Account
* **voter** - Der Account, mit dem du dein Vote abgeben willst
* **author** - Wem du ein Vote geben willst
* **permlink** - welchem Beitrag/Kommentar du ein Vote geben willst
* **weight** - Die Gewichtung deines Votes, 1-10000, 10000 entspricht 100%
Nur wenn ihr sehr viel HivePower habt, macht es Sinn einen kleinen Vote abzugeben. Wenn ihr eine negative Zahl zwischen -1 und -10000 nutzt, gebt ihr ein downvote, wenn ihr 0 nutzt, wird ein vorheriger vote/downvote zurückgenommen.

## Achtung/Wichtig
**Auch wenn ich am Ende ein Beispiel auf jsfiddel hier verlinke, verwende nie dein Postingschlüssel auf irgendeiner Webseite! Nutze das Script wenn nur bei dir aufm PC für Tests. Wenn jemand in den Besitz deines Postingschlüssels kommt, kann er damit einiges machen, u.a. Posten und Voten!**


## weight als Zahl übergeben
![](https://images.ecency.com/DQmNgjuNYQ5oSkV5t9Jy1nrRaoEEsFhNbwJKwtdfZ32WTRA/grafik.png)
Solltet ihr vergessen, weight als Zahl zu übergeben, so erhaltet ihr in der Konsole obiges zu sehen.

## Vote erfolgreich abgesendet
![](https://images.ecency.com/DQmZ5d29hPDw4QMqcV1A7b61g7CFuQCU8PrqSfriRL4NBZa/grafik.png)

So sieht es aus, wenn der Vote erfolgreich an die Blockchain übertragen wurde, aber Vorsicht, denn ihr könnt auch alten Beiträgen ein Vote geben, was aber kein Sinn macht, denn der Autor bekommt nur für Votes innerhalb von 7 Tagen ein Reward.

Dass dies möglich ist, seht ihr hier auf dem Screenshot:
![](https://images.ecency.com/DQmdmUftrqjWnY2x9MAq5VVuP6sZ8fpL5DhRZKWFB3yAMZ8/grafik.png)

Da ist das letzte Vote vor meinem bereits 8 Tage alt. Der Beitrag somit schon älter als 7 Tage alt. Soweit ich sehe, verliert man aber keine Votingpower, wenn man es doch macht. 

## Doppel Vote
![](https://images.ecency.com/DQmcXM9cXepHZdzwHV4Zhv7Mh2dUt8UbyMf6hNDMpcnhdjj/grafik.png)
Wenn ihr bereits mit der gleichen Gewichtung gevotet habt, erhaltet ihr obige Fehlermeldung.

## fehlerhafter Permlink/Autor
![](https://images.ecency.com/DQmQ5E6dLgqgAZsSTemnbhNJbB6mJExtq9LmGubDfvq4TdD/grafik.png)
So sieht die Fehlermeldung aus, wenn ihr einen Permlink nutzt, den es bei dem Autor nicht gibt oder auch wenn es den Autor gar nicht gibt.

[Hier](https://jsfiddle.net/hive_coding/6d4n807r) der Code auf jsfiddle. **Nochmal die Warnung nutzt dort nicht euren Schlüssel!**

Ich hoffe es war verständlich. Wenn ihr Fragen habt, dann schreibt ein Kommentar und am besten erwähnt ihr meinen Account @mein-senf-dazu, dann bekomme ich das eher mit.

👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 87 others
👎  
properties (23)
authorhive-coding
permlinkhivejs-how-to-vote-wie
categoryhive
json_metadata{"links":["https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#vote","https://jsfiddle.net/hive_coding/6d4n807r","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast","https://gitlab.syncad.com/hive/hive-js/tree/master/doc#vote","https://jsfiddle.net/hive_coding/6d4n807r"],"image":["https://images.ecency.com/DQmYrGv54y1xPw2M3gQz2A4QZAznBntxC7JRqpmE5HjTp13/grafik.png","https://images.ecency.com/DQmNgjuNYQ5oSkV5t9Jy1nrRaoEEsFhNbwJKwtdfZ32WTRA/grafik.png","https://images.ecency.com/DQmZ5d29hPDw4QMqcV1A7b61g7CFuQCU8PrqSfriRL4NBZa/grafik.png","https://images.ecency.com/DQmdmUftrqjWnY2x9MAq5VVuP6sZ8fpL5DhRZKWFB3yAMZ8/grafik.png","https://images.ecency.com/DQmcXM9cXepHZdzwHV4Zhv7Mh2dUt8UbyMf6hNDMpcnhdjj/grafik.png","https://images.ecency.com/DQmQ5E6dLgqgAZsSTemnbhNJbB6mJExtq9LmGubDfvq4TdD/grafik.png"],"thumbnails":["https://images.ecency.com/DQmYrGv54y1xPw2M3gQz2A4QZAznBntxC7JRqpmE5HjTp13/grafik.png","https://images.ecency.com/DQmNgjuNYQ5oSkV5t9Jy1nrRaoEEsFhNbwJKwtdfZ32WTRA/grafik.png","https://images.ecency.com/DQmZ5d29hPDw4QMqcV1A7b61g7CFuQCU8PrqSfriRL4NBZa/grafik.png","https://images.ecency.com/DQmdmUftrqjWnY2x9MAq5VVuP6sZ8fpL5DhRZKWFB3yAMZ8/grafik.png","https://images.ecency.com/DQmcXM9cXepHZdzwHV4Zhv7Mh2dUt8UbyMf6hNDMpcnhdjj/grafik.png","https://images.ecency.com/DQmQ5E6dLgqgAZsSTemnbhNJbB6mJExtq9LmGubDfvq4TdD/grafik.png","https://images.ecency.com/DQmYrGv54y1xPw2M3gQz2A4QZAznBntxC7JRqpmE5HjTp13/grafik.png","https://images.ecency.com/DQmNgjuNYQ5oSkV5t9Jy1nrRaoEEsFhNbwJKwtdfZ32WTRA/grafik.png","https://images.ecency.com/DQmZ5d29hPDw4QMqcV1A7b61g7CFuQCU8PrqSfriRL4NBZa/grafik.png","https://images.ecency.com/DQmdmUftrqjWnY2x9MAq5VVuP6sZ8fpL5DhRZKWFB3yAMZ8/grafik.png","https://images.ecency.com/DQmcXM9cXepHZdzwHV4Zhv7Mh2dUt8UbyMf6hNDMpcnhdjj/grafik.png","https://images.ecency.com/DQmQ5E6dLgqgAZsSTemnbhNJbB6mJExtq9LmGubDfvq4TdD/grafik.png"],"users":["mein-senf-dazu","mein-senf-dazu"],"tags":["hive","coding","deutsch","hive-engine","hivejs","hive-coding","pob","hive-js"],"description":"","app":"ecency/3.0.28-vision","format":"markdown+html"}
created2022-10-29 09:52:33
last_update2022-10-29 09:52:33
depth0
children5
last_payout2022-11-05 09:52:33
cashout_time1969-12-31 23:59:59
total_payout_value16.574 HBD
curator_payout_value16.543 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,195
author_reputation7,401,300,735,103
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id117,878,610
net_rshares52,536,986,714,129
author_curate_reward""
vote details (152)
@dragon-ti ·
Danke dir 😎
properties (22)
authordragon-ti
permlinkre-hive-coding-2022114t235417738z
categoryhive
json_metadata{"tags":["hive","coding","deutsch","hive-engine","hivejs","hive-coding","pob","hive-js"],"app":"ecency/3.0.28-vision","format":"markdown+html"}
created2022-11-04 22:54:18
last_update2022-11-04 22:54:18
depth1
children0
last_payout2022-11-11 22:54:18
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_length11
author_reputation120,953,933,747,564
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,069,115
net_rshares0
@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=%5B197%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
properties (22)
authorecency
permlinkre-20221029t152618697z
categoryhive
json_metadata{"tags":["ecency"],"app":"ecency/3.0.20-welcome","format":"markdown+html"}
created2022-10-29 15:26:18
last_update2022-10-29 15:26:18
depth1
children0
last_payout2022-11-05 15:26:18
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_reputation613,590,122,884,308
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id117,885,523
net_rshares0
@hivebuzz ·
Congratulations @hive-coding! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@hive-coding/payout.png?202210291642"></td><td>You received more than 10 HP as payout for your posts, comments and curation.<br>Your next payout target is 50 HP.<br><sub>The unit is Hive Power equivalent because post and comment rewards can be split into HP and HBD</sub></td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@hive-coding) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/halloween/@hivebuzz/halloween-2022"><img src="https://images.hive.blog/64x128/https://i.imgur.com/jeLRU6l.png"></a></td><td><a href="/halloween/@hivebuzz/halloween-2022">Trick or Treat - Share your scariest story and win your Halloween badge</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pud-202211"><img src="https://images.hive.blog/64x128/https://i.imgur.com/805FIIt.jpg"></a></td><td><a href="/hive-122221/@hivebuzz/pud-202211">Hive Power Up Day - November 1st 2022</a></td></tr></table>

###### Support the HiveBuzz project. [Vote](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22199%22%5D&approve=true) for [our proposal](https://peakd.com/me/proposals/199)!
properties (22)
authorhivebuzz
permlinknotify-hive-coding-20221029t165944
categoryhive
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-10-29 16:59:45
last_update2022-10-29 16:59:45
depth1
children0
last_payout2022-11-05 16:59:45
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_length1,590
author_reputation369,201,072,934,919
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id117,887,614
net_rshares0
@pizzabot ·
<center>🍕 PIZZA !
 @hive-coding! The Hive.Pizza team manually upvoted your post.

<sub>Learn more at https://hive.pizza!</sub></center>
properties (22)
authorpizzabot
permlinkre-hivejs-how-to-vote-wie-20221029t204923z
categoryhive
json_metadata"{"app": "beem/0.24.19"}"
created2022-10-29 20:49:24
last_update2022-10-29 20:49:24
depth1
children0
last_payout2022-11-05 20:49:24
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_length135
author_reputation7,452,962,500,466
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id117,892,809
net_rshares0
@poshtoken ·
$0.03
https://twitter.com/1335995374528507907/status/1588639511289876482
<sub> The rewards earned on this comment will go directly to the people( @dragon-ti ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
👍  
properties (23)
authorposhtoken
permlinkre-hive-coding-hivejs-how-to-vote-wie-2752
categoryhive
json_metadata"{"app":"Poshtoken 0.0.1","payoutToUser":["dragon-ti"]}"
created2022-11-04 21:10:06
last_update2022-11-04 21:10:06
depth1
children0
last_payout2022-11-11 21:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.025 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length268
author_reputation5,171,421,827,842,018
root_title"Hivejs: How to vote - Wie man ein Vote abgibt #4"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id118,066,901
net_rshares112,260,499,483
author_curate_reward""
vote details (1)