This is the third part to a series of tutorials.
The goal is to produce a hands-on guide for people who want to jump straight into developing tools for STEEM.
Whenever I query data 'from the blockchain', I have to connect to a node that runs the corresponding API plugin to my request. I just got reminded of how little I understand about this.
I will stick to what works for me and explain as best as I can.
For this guide I will treat the API like a black box and will look at beem's modules only. Most of beem's methods closely reflect the underlying API calls, though.
These are beem's modules
In the last part, I used the
from beem.blockchain import Blockchain blockchain = Blockchain()
blockchain as of the class Blockchain like defined in:
In the documentation you can look up, which parameters the different methods accept and what data type they will return.
head_block = blockchain.get_current_block_num()
get_current_block_num, returns an
As an example, I will go through some methods of the
from beem.account import Account test_account = Account(account = 'holger80') print(test_account.balances)
This returns a dictionary, but the print() function will print it as a string automagically.
from beem.account import Account test_account = Account(account = "holger80") print(test_account.get_balances())
This returns the same dictionary as the
balances method does.
beem has some higher level functions, which are abstracted from the raw API data:
from beem.account import Account test_account = Account(account = "holger80") print(test_account.get_voting_power()) print(test_account.get_voting_power(with_regeneration = False))
By default, the parameter
with_regeneration is set to
The regeneration however, is being calculated for you by beem.
The STEEM API will always only return the voting power at the time of the last vote.
history() method deserves its own chapter.
Sadly, the default node set in beem does not support it at the moment.
I have to set the node by hand like this:
from beem import Steem from beem.instance import set_shared_steem_instance steemit_api = Steem(node=["https://api.steemit.com"]) set_shared_steem_instance(steemit_api)
This makes our black box API work again.
Leave this in front of all examples from now on, for good measure.
For most purposes,
history_reverse is the more useful function, but is derived from
history anyways - It is just the other way around starting at the latest block, going backwards.
from beem.account import Account from beem.blockchain import Blockchain blockchain = Blockchain() head_block = blockchain.get_current_block_num() test_account = Account("holger80") for operation in test_account.history_reverse(start = head_block, stop = head_block - 10000, use_block_num = True): print(operation)
This returns all operations during the last 10000 blocks for the specified account.
There are more examples in the documentation.
This should enable you to explore all of beem's modules and methods.
If you want me to explain a specific method more closely, let me know in the comments or in chat.
Can you calculate the average of your last 10 curation rewards ?