A start in scripting on the HIVE Blockchain

in STEMGeeks3 months ago

I've been interested in trying to understand the technical aspects of the Hive Blockchain for some time, so this week I thought it was about time to try my hand at doing a bit of scripting to interact with the blockchain. I am coming to this from a long term background of programing, (starting with machine code on a ZX81 way back in .... 1981) but I have no experience of modern scripting languages so it'll be an interesting learning experience if nothing else.

I started from scratch by downloading and installing Visual Studio Code from Microsoft and installing the default Python package.

My next step was to find a way to actually read information held on the HIVE Blockchain. Hunting through many posts I came across several mentions of the beem api (beem - Unofficial Python Library for HIVE and STEEM). I did a download from the holgern/beem GitHub page and installed via the VSCode terminal window with:

pip install -U beem

It should be noted that this api hasn't been updated for about 3 years so may well have been abandoned by its creator.

Everything appeared to run as expected, so now was time to test things had been installed correctly. Referring to https://beem.readthedocs.io/en/latest/beem.account.html I copied the following code (Obviously having changed the account name to my own)


from beem.account import Account
from beem import Hive
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
stm = Hive(node=nodelist.get_hive_nodes())
account = Account("keyshall", blockchain_instance=stm)
print(account)
print(account.balances)

This produced the following output:


<Account keyshall>
{'available': [0.010 HIVE, 0.029 HBD, 93927.421216 VESTS], 'savings': [0.000 HIVE, 0.000 HBD], 'rewards': [0.000 HIVE, 0.000 HBD, 0.000000 VESTS], 'total': [0.010 HIVE, 0.029 HBD, 93927.421216 VESTS]}

The HIVE and HBD balances are correct for my account so I'll take that as a successful test. I'll work out how to see how many VESTS I have and how to convert that to Hive Power later.

I have a feeling that today was the easy part of this adventure, but I'll try to keep you up to date with how things progress.

Sort:  

Hope you'll stick around!

!discovery 19


This post was shared and voted inside the discord by the curators team of discovery-it
Join our Community and follow our Curation Trail
Discovery-it is also a Witness, vote for us here
Delegate to us for passive income. Check our 80% fee-back Program

Congratulations @keyshall! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 100 upvotes.
Your next target is to reach 200 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Hive Power Up Day - July 1st 2024

The Hive blockchain is full of material on how to use scripts to talk to the public-RPC nodes and front-ends use this data to show you much of what you see. Unfortunately, there is a lot of outdated material as well. You're going to find you will never get link errors while using Python. 😂 APIs have changed somewhat and they are not available everywhere. The good news is, most Hive APIs don't try to invent new APIs in their wrapper, they are either super thin or they duplicate the raw JSON API with a change to camel case. Ecency is open source you can learn about the APIs just by reading the source code. Look in the "store" subdirectory. 👀

Thank you for your input. I've certainly realised I need to do an awful lot of reading.