hive-engine: How to retrieve data - Wie Daten abrufen

@hive-coding · 2023-03-19 12:47 · Programming & Dev

Mein letzter Beitrag ist leider schon fast einen Monat her, in dem ich erklärt habe, wie man mithilfe der Hivekeychain einen Kommentar an die Blockchain sendet.

Hive-Engine

Wer die Hive-Engine nicht kennt, der muss neu bei Hive sein. Ok, vielleicht nutzen manche von euch Tribaldex, ich nutze aus Gewohnheit Hive-engine.

Wer Daten abrufen will, kann dies ganz einfach mit sscjs machen. Am einfachsten ist es, indem man einfach die Dateien einbindet:




Find

find(contract, table, query, limit = 1000, offset = 0, indexes = [], callback = null) 

Mit der find-Methode kann man Daten abrufen, dafür benötigt man zunächst contract und table.

Contract

Aber was kann man als contract angeben?

Welche contracts es gibt, findet ihr hier. Der Name jeder js-Datei kann verwendet werden.

Zu diesem Zeitpunkt sind es folgende Contracts: 1. airdrops 2. claimdrops 3. comments 4. crittermanager 5. dice 6. distribution 7. hivepegged 8. inflation 9. market 10. marketmaker 11. marketpools 12. mining 13. nft 14. nftairdrops 15. nftauction 16. nftmarket 17. packmanager 18. sscstore 19. tokenfunds 20. tokens 21. witnesses

Da frage ich mich gerade, wo kann man denn NFT versteigern bzw. ersteigern? Da dort nur wenige Auktionen drin sind, scheint es noch recht neu zu sein.

Tables

Nun benötigen wir noch die Tabellen der Contracts. Diese können wir mit der Funktion getContractInfo abrufen.

getContractInfo(contract, callback  =  null)

Mit der Funktion erhalten wir neben dem Code des contractes auch die Tabellennamen. Diese beginnen immer mit dem Contractnamen und einem Unterstrich, jedoch müssen diese ohne diesem in der find-Methode angegeben werden.

Contract hat somit die Tabellen balances, contractsBalances, delegations, params, pendingundelegations, pendingunstakes und tokens als Tabellen.

Um die Kontostände abzurufen, nutzen wir somit die find-Methode wie folgt:

ssc.find('tokens', 'balances', { }, 1000, 0, [], (err, result) => {
console.log(err, result);
});

Hier findet ihr ein kleines Beispiel auf jsFiddle. Ihr könnt in dem Beispiel die Contracts auswählen und dann eine der Tabellen des Contracts. Es wird dann ein Datensatz aus der Tabelle ausgegeben.

EN

My last post was unfortunately almost a month ago, in which I explained how to send a comment to the blockchain using the Hivekeychain.

Hive engine

If you don't know about the Hive Engine, you must be new to Hive. Ok, maybe some of you use Tribaldex, I use Hive-engine out of habit.

If you want to retrieve data, you can do it easily with sscjs. The easiest way is to simply include the files:




Find

find(contract, table, query, limit = 1000, offset = 0, indexes = [], callback = null) 

The find method can be used to retrieve data, for which you first need contract and table.

Contract

But what can you specify as a contract?

You can find out which contracts are available here. The name of each js file can be used.

At this time, the following contracts are available: 1. airdrops 2. claimdrops 3. comments 4. crittermanager 5. dice 6. distribution 7. hivepegged 8. inflation 9. market 10. marketmaker 11. marketpools 12. mining 13. nft 14. nftairdrops 15. nftauction 16. nftmarket 17. packmanager 18. sscstore 19. tokenfunds 20. tokens 21. witnesses

I was just wondering, where can NFT be auctioned off? Since there are only a few auctions there, it seems to be quite new.

Tables

Now we need the tables of the contracts. We can get them with the function getContractInfo.

getContractInfo(contract, callback = null)

With this function we get the code of the contract as well as the table names. These always start with the contract name and an underscore, but they have to be given without it in the find method.

Contract thus has the tables balances, contractsBalances, delegations, params, pendingundelegations, pendingunstakes and tokens as tables.

To retrieve the account balances, we thus use the find method as follows:

ssc.find('tokens', 'balances', { }, 1000, 0, [], (err, result) => {
console.log(err, result);
});

Here you can find a small example on jsFiddle. You can select the contracts in the example and then one of the tables of the contract. A record from the table is then output.

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

#hive-169321 #hive #coding #deutsch #hive-engine #hivejs #hive-coding #pob #hive-js #dev
Payout: 0.000 HBD
Votes: 57
More interactions (upvote, reblog, reply) coming soon.