RE: Python Libraries: No More BEEM

You are viewing a single comment's thread:

I think you can use the ‘requests’ library to make HTTP requests to the Hive API.

Suppose you have a function that publishes a publication using BEEM:



from beem import Hive

def publicar_mensaje(usuario, clave_privada, mensaje):
Hive = Hive(keys=[clave_privada])
hive.post(mensaje, author=usuario)


You can replace it using the Hive API directly with requests:



import requests

def publicar_mensaje(usuario, clave_privada, mensaje):
url = "https://api.hive.blog/rpc"
payload = {
"jsonrpc": "2.0",
"method": "condenser_api.post",
"params": [usuario, clave_privada, "", mensaje, "", False],
"id": 1,
}
response = requests.post(url, json=payload)
print(response.json())



Or something like that. It's a matter of investing another weekend and doing the relevant tests.



0
0
0.000
1 comments
avatar
(Edited)

Or something like that. It's a matter of investing another weekend and doing the relevant tests.

This is tested:

import requests

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

Save as api.py and import your own custom calls 🙂

response is json, I handle that like this:

import api

def get_last_irreversible_block_num(node_url):
    response = api.get_properties(node_url)
    num = int(response.json()["result"]['last_irreversible_block_num'])
    return num

I think this is clean enough.
Use https://developers.hive.io/ api refenrence for other calls.

Please don't ask me why I called a function get_last_irreversible_block_num 🤣
I just copy pasted this from older code and thought it was a neat example for @slobberchops 😜

However: transaction signing isn't trivial, I'd recommend a library like BEEM.


Sorry for the edits.

Hope this saves someone some time.
Follow my blog 😁 for more.

0
0
0.000