Wie man mit Javascript in die Hive Blockchain schreibt

Hallo liebe Hiveaner,

(english see below)

heute ist für mich ein ganz besonderer Tag. Ich habe es nach jahrelangem Lernen und Ausprobieren geschafft, mit Hilfe eines Javascriptprogrammes in die Hive Blockchain hinein zu schreiben. Das ist für mich ein riesiger Meilenstein, der höchste Programmier-Gipfel, auf dem ich je gestanden habe.

grafik.png
Dieses Bild wurde erschaffen mit https://creator.nightcafe.studio/

Ich will euch natürlich nicht vorenthalten wie es geht. Im nachhinein sieht es ja auch ganz leicht aus ;-)

Upvote

Hier ist mein Javascript Code um ein Upvote an ein bestehenden Post zu geben:

import hive from '@hiveio/hive-js';
const privateKey = '5J...';
hive.api.setOptions({ url: 'https://api.hive.blog' });
const voter = 'anobel';
const author = 'achimmertens';
const permlink = 'weekly-statistics-for-the-beerbot-rvz3l6';
hive.broadcast.vote(
  privateKey,
  voter,
  author,
  permlink,
  5000, // entspricht 50% Upvote
  function(err, result) {
    console.log(err, result);
  }
);

Diesen Code habe ich in eine Datei namens vote.js gespeichert. Die liegt in einem Projektordner, der mit Github verbunden ist. D.h. ihr könnt den Code hier im Original sehen.

Nach dem Erstellen des Scripts muss Node aktuallisiert werden, bzw. das hive-js Modul geladen werden:

$ npm i @hiveio/hive-js

Damit aber noch nicht genug (bei mir). Wegen der Fehlermeldung:

    $ node vote.js
    (node:4488) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 

musste ich dann noch in die package.json hinzufügen:

"type": "module",

grafik.png

Nun kann man das Script wie folgt ausführen:

$ node vote.js

Man erhält eine Rückbestätigung:

null {
  id: 'd2c36097286aa26c965205c3080fd98e9579d8ab',
  ref_block_num: 12506,
  ref_block_prefix: 1667678884,
  expiration: '2023-06-15T04:43:03',
  operations: [ [ 'vote', [Object] ] ],
  extensions: [],
  signatures: [
    '1f56a8a4d779f39c6f1eaf1448960999f550c725cbad46cae228468d603043dfb130adf7b2e6e0d57bf7dcaf00918c0a22f6aeb8c70718c08b006124a6c3608973'
  ]
}

Und tatsächlich erkennt man, dass der Voter "anobel" in der Peakd-Ansicht erscheint:

grafik.png

Aber damit nicht genug. Jetzt will ich mehr.

Kommentar

Mit folgendem Code bin ich in der Lage einen Kommentar zu schreiben:

import hive from '@hiveio/hive-js';
import config from './config.js';
const privateKey = config.privateKey;
hive.api.setOptions({ url: 'https://api.hive.blog' });
const parentAuthor = 'achimmertens';
const parentPermlink = 'weekly-statistics-for-the-beerbot-rvz3l6';
const author = 'anobel';
const permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
const title = '';
const body = 'Hallo, hier ist anobel. Dies ist mein erster Kommentar seit langem.';
hive.broadcast.comment(
  privateKey,
  parentAuthor,
  parentPermlink,
  author,
  permlink,
  title,
  body,
  { tags: ['test'], app: 'test/0.1' },
  function(err, result) {
    console.log(err, result);
  }
);

Und Tadaaa, hier ist das Ergebnis:

grafik.png

Wie geht es weiter

Da mir nun viele Türen offen stehen, möchte ich auch ausprobieren, wie man ganze Posts erstellt (Soll einfach sein, indem man einen Titel im Kommentarfeld einfügt). Ich möchte aber auch automatisiert Hive und Nobel-Token verschicken können. Ich habe da ein paar Ideen, die sind aber noch nicht Spruchreif.

Fazit:

Der Damm ist gebrochen.

grafik.png
origin: https://dreamlike.art/create

Ich kann nun meine Reports, die ich tatsächlich (teilautomatisiert erstelle und) noch von Hand in die Blockchain schreibe, zumindest im Prinzip ganz automatisieren. Sicher sind da noch weitere Berge zu erklimmen, aber der wichtigste Schritt ist jetzt getan.

Im Übrigen bin ich sehr dankbar für die neuen Möglichkeiten der KI. Ohne ChatGPT bzw. Bing hätte es wohl deutlich länger gedauert, um an diese Ergebnisse zu kommen. Allerdings spucken diese neuen Intelligenzen nicht auf Anhieb raus was gewünscht ist oder funktionert. Aber mit ein bischen Backgroundwissen und Einlesen in die Hive-API und Hive-Doku kommt man dann irgendwann doch voran.

Ich habe da schon lange darauf hin gearbeitet und bin so glücklich, dass ich heute Abend zusammen mit meiner Frau eine Flasche Sekt aufmache.

grafik.png
origin: https://dreamlike.art/create

In diesem Sinne: Prost!


English

Hello dear Hiveans,

today is a very special day for me. After years of learning and trying, I managed to write into the Hive blockchain using a Javascript program. This is a huge milestone for me, the highest programming summit I've ever stood on.

graphic.png
This image was created with https://creator.nightcafe.studio/

Of course I don't want to withhold from you how it's done. In hindsight it looks easy ;-)

Upvote

Here is my javascript code to upvote an existing post:

import hive from '@hiveio/hive-js';
const privateKey = '5J...';
hive.api.setOptions({ url: 'https://api.hive.blog' });
const voter = 'anobel';
const author = 'achimmertens';
const permlink = 'weekly-statistics-for-the-beerbot-rvz3l6';
hive.broadcast.vote(
   private key,
   voter,
   author,
   permlink,
   5000, // equals 50% upvote
   function(err, result) {
     console.log(err, result);
   }
);

I saved this code in a file called vote.js. It's in a project folder connected to Github. That means you can see the original code here.

After creating the script, Node must be updated or the hive-js module must be loaded:

$npm i @hiveio/hive-js

But that's not all (for me). Because of the error message:

$ node vote.js
(node:4488) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

I then had to add to the package.json:

"type": "module",

graphic.png

Now you can run the script as follows:

$ node vote.js

You will receive a confirmation:

null {
   ID: 'd2c36097286aa26c965205c3080fd98e9579d8ab',
   ref_block_num: 12506,
   ref_block_prefix: 1667678884,
   expiration: '2023-06-15T04:43:03',
   operations: [ [ 'vote', [Object] ] ],
   extensions: [],
   signatures: [
     '1f56a8a4d779f39c6f1eaf1448960999f550c725cbad46cae228468d603043dfb130adf7b2e6e0d57bf7dcaf00918c0a22f6aeb8c70718c08b006124a6c3608 973'
   ]
}

And indeed you can see that the voter "anobel" appears in the Peakd view:

graphic.png

But that's not all. Now I want more.

comment

With the following code I am able to write a comment:

import hive from '@hiveio/hive-js';
import config from './config.js';
const privateKey = config.privateKey;
hive.api.setOptions({ url: 'https://api.hive.blog' });
const parentAuthor = 'achimmertens';
const parentPermlink = 'weekly-statistics-for-the-beerbot-rvz3l6';
const author = 'anobel';
const permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
const title = '';
const body = 'Hello, this is anobel. This is my first comment in a long time.';
hive.broadcast.comment(
   private key,
   parentAuthor,
   parentPermLink,
   author,
   permlink,
   title,
   body,
   { tags: ['test'], app: 'test/0.1' },
   function(err, result) {
     console.log(err, result);
   }
);

And tadaaa, here is the result:

grafik.png

What's next

Now that many doors are open to me, I would also like to try how to create whole posts (should be easy by putting a title in the comment field). But I would also like to be able to send Hive and Nobel tokens automatically. I have a few ideas, but they're not ready for decision yet.

Conclusion:

The dam has broken.

graphic.png
origin: https://dreamlike.art/create

I can now fully automate my reports, which I actually create (partially automatically and) still write into the blockchain by hand, at least in principle. There are certainly more mountains to climb, but the most important step has now been taken.

Incidentally, I am very grateful for the new possibilities of AI. Without ChatGPT or Bing it would have taken much longer to get these results. However, these new intelligences do not immediately spit out what is desired or works. But with a bit of background knowledge and reading into the Hive-API and Hive-doku you get there.

I've been working toward this for a long time and I'm so happy that I'm opening a bottle of sparkling wine with my wife tonight.

grafik.png
origin: https://dreamlike.art/create

Cheers, Achim

Sort:  

!PGM
!PIZZA
!CTP

Sent 0.1 PGM - 0.1 LVL- 1 STARBITS - 0.05 DEC - 1 SBT - 0.1 THG - 0.000001 SQM - 0.1 BUDS - 0.01 WOO tokens

remaining commands 8

BUY AND STAKE THE PGM TO SEND A LOT OF TOKENS!

The tokens that the command sends are: 0.1 PGM-0.1 LVL-0.1 THGAMING-0.05 DEC-15 SBT-1 STARBITS-[0.00000001 BTC (SWAP.BTC) only if you have 2500 PGM in stake or more ]

5000 PGM IN STAKE = 2x rewards!

image.png
Discord image.png

Support the curation account @ pgm-curator with a delegation 10 HP - 50 HP - 100 HP - 500 HP - 1000 HP

Get potential votes from @ pgm-curator by paying in PGM, here is a guide

I'm a bot, if you want a hand ask @ zottone444


PIZZA!

$PIZZA slices delivered:
@jeyf123(2/5) tipped @achimmertens
torran tipped achimmertens

Meine Hochachtung dafür. Ich verstehe, was du meinst, wenn du sagst du hast Jahre gebraucht. Immer wieder versuche ich in die Welt der Programmierung zu tauchen und scheitere an meinem Unvermögen diese Dinge richtig zu verstehen, oder einfach den Aufwand zu betreiben das alles zu lernen.

Momentan versuche ich gerade (erneut) mich mit Python anzufreunden, mithilfe des Rheinwerk Verlags.https://openbook.rheinwerk-verlag.de/python/
Das habe ich mir sequenziell als PDF gespeichert, dann zusammengefügt und lerne es langsam von Kapitel zu Kapitel. ChatGPT verwende ich dafür, wenn ich Dinge im Text nicht verstehe (oder manchmal) missinterpretiere. Das ist eine immens große Hilfe.

Hab deinen Post gebookmarked, vielleicht kann ich dieses Wissen später ja mal verwenden. Danke dafür.

!BEER
!LUV
!PIZZA

Hallo @jeyf123,
deinen ersten Satz kann ich für mich wiederholen, geht mir auch so. Das ist wie das Bestimmen von Pflanzenarten in einem fremden Djungel. Aber davon darf man sich nicht klein machen lassen. Man muss auf die Erfolge achten. Mir hilft dabei ein Erfolgstagebuch.

Danke für deine Antwort und noch viel Glück und Erfolg beim weiterlernen.

Gruß, Achim

Danke, ich versuche konsequent zu bleiben(was mir sehr schwer fällt)

Hallo Achim, dass sieht ja echt cool aus. Ichj kopiere mir mal deinen Text. Im übrigen wurde dieser Kommentar auch aus einem Javascript Programm geschrieben :-)