Hive As A Black Box

in #hive5 months ago

A Hacker's Guide to Hive

It has been a while since I last tried posting a tutorial series.
As I am getting closer to releasing my first 'real app' for Hive, I want to blog about its development and what thoughts have gone into the system I am using.

Developing for Hive (blockchain) has some unique challenges.
Instead of describing these abstract problems, I'll try to 'hack' my way into it.
This is a hands-on approach.

Inspired by: A Hackers' Guide to Language Models, by Jeremy Howard
I watched all sorts of talks and presentations on LMs. This guide actually made it 'click' for me. He brushes over the necessary theory you need to know, but then jumps straight into 'how to use it'. Turns out, he is not some random dude, but his 'invention' caused the current revolution in AI. Not comparing myself to him, but I let his 'hacker' approach inspire me.

blackbox.png

Hive as a black box

Let's say you know a little bit about

  • computers
  • programming

...you found Hive and want to build a service, a 'bot', a game...

what is Hive?

...you go to https://hive.io/
It's blockchain. It's fast. It's scalable...

  • what does it do?
  • how does it work?

black box

In the following I try to work out the only things you absolutely need to know.
The most practical approach; Treat Hive like a black box.

hive_tables_small.png

Hive State

API reference:

example

Python + requests:

import requests

hive_api_url = 'https://api.hive.blog'

def hive_api_get_properties(url):
    data = '{"jsonrpc":"2.0", "method":"database_api.get_dynamic_global_properties", "id":1}'
    return requests.post(url, data=data)     

response = hive_api_get_properties(hive_api_url)

result = response.json()["result"]

print(result)
  • pip install requests
    I try to avoid dependencies, but requests just makes this so much cleaner...
  • save file as test.py, run like: python test.py

If you need any help with Python, please ask below.

Javascript in browser:

<!DOCTYPE html>
<html>
<script>

const hive_api_url = 'https://api.hive.blog'

const hive_api_get_properties = async(url) => {
    fetched = await fetch(
        url, {
            method: 'POST',
            body: JSON.stringify({
                "id": 1,
                "jsonrpc": "2.0",
                "method": "database_api.get_dynamic_global_properties"                
            })
        }        
    )
    let response = await fetched.json()
    console.log(response['result'])
}

hive_api_get_properties(hive_api_url)

</script>
</html>
  • save as test.html, open with browser
  • check out console

If you need any help with JS, please ask below.

What you need to know

  • You can access Hive's API through https.
  • Hive's state changes;
    Make the same request later, the response can be different.

Hive's a black box, that changes state over time.


Please let me know, if this interests you and if I should tag you in the next post.
Happy New Year!

Sort:  

I would be happy if you could tag me in your next post! I always find such things super interesting - I'm an absolute newbie in this area, but one never stops learning!

!PIZZA

Did you try one of the scripts above?

Yes. At first I got the error:

Bildschirmfoto 2024-01-02 um 11.06.41.png

Due to the requests are missing. I had to do pip3 install requests. pip install requests lead to an error. Maybe because I am on Mac.
I am a total noob in the way of programming.

Bildschirmfoto 2024-01-02 um 11.10.28.png

It's quit cool to see the HBD Supply etc.!

Wäre es in Theorie möglich die upcoming rewards für verschiedene Accounts auszugeben? In Peakd gibt es ja die Möglichkeit sich die payouts anzeigen zu lassen, die in den nächsten 7 Tagen kommen.

Ich seh das erst jetzt, weil ich gerade einen Folgebeitrag verfasse.
Ja für 'pending payouts' gibt es verschiedene direkte API-calls:

https://developers.hive.io/apidefinitions/#database_api.get_comment_pending_payouts

(für einen Beitrag)

https://developers.hive.io/apidefinitions/#account_history_api.get_account_history

(für alle Beiträge eines Autoren)

Ich empfehle, einfach die API docs (https://developers.hive.io/apidefinitions/) zu öffnen und dann per ctrl+f alles zu durchsuchen, bis du den call findest, der am besten zu deinem Problem passt.
Hoffe das hilft.

Danke!
Damit werde ich mich mal etwas auseinander setzen! Bin als blutiger Anfänger aktuell auf https://www.freecodecamp.org/ am versuchen mir bisschen etwas beizubringen.
Freu mich schon auf deinen nächsten Beitrag :)

Falls du irgendwelche konkreten Fragen hast, schreib mich gern an auf Discord.

OK - Let's start with this...
I am a programming dummy! Almost completely! - So, help me God, if I understood anything! 😳🙅‍♀️
Still! Funny but true, I got intrigued! (Although I'm not sure for what!?!) 😁
However, I'm curious to find out what kind of "'real app' for Hive" you are going to make and how a programming dummy like me might be able to use it (and for what).
So, feel free to tag me in your next post.

I try to avoid dependencies, but requests just makes this so much cleaner...

Are we talking about the same dependencies, which is in Linux softwares? I used Linux for years, and I often saw messages about dependencies, but I still do not really understand it. They made the installation of multiple programs harder. I am not into programming much, but I try to understand the concept behind it.

I had no idea about the existence of a similar guide called "A Hackers' Guide to Language Models" written by Jeremy Howard. By the way, I like it when developers share their personal experiences and thoughts about developing on blockchain platforms. I find it easier reading to understand the work behind the development of blockchain-based applications or solutions.

Like you, I am also interested in developing applications on Hive. Maybe I can find some valuable ideas or inspiration within the guide for my own projects. Thanks for sharing :)

PIZZA!

$PIZZA slices delivered:
@chrislybear(2/5) tipped @felixxx