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, to be more specific, the hive.broadcast.vote function.
As you can see, this expects 5 parameters:
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!
If you forget to pass weight as a number, you will see the above in the console.
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:
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.
If you have already voted with the same weighting, you will get the above error message.
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 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 , then I get that sooner.
Translated with www.DeepL.com/Translator (free version)
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 einmal an, um genauer zu sein, die Funktion hive.broadcast.vote.
Wie ihr sehen könnt, erwartet diese 5 Parameter:
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!
Solltet ihr vergessen, weight als Zahl zu übergeben, so erhaltet ihr in der Konsole obiges zu sehen.
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:
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.
Wenn ihr bereits mit der gleichen Gewichtung gevotet habt, erhaltet ihr obige Fehlermeldung.
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 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 , dann bekomme ich das eher mit.