Hive As A Black Box

felixxx(72)
Published in
#hive
Words
358
Reading
2 min
Listen
Play
3y

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!

Hive As A Black Box | Ecency