create account

Hacer consultas a la blockchain Hive mediante APIs y Python by enrique89

View this thread on: hive.blogpeakd.comecency.com
· @enrique89 ·
$57.63
Hacer consultas a la blockchain Hive mediante APIs y Python
<center>![image.png](https://files.peakd.com/file/peakd-hive/enrique89/23t76t9qhNjrg7wTwPXUDVNPkdko1Wfu7jjwdWBaKKEBcsLTitD4ekLGHvUAf66u8TaX6.png)</center>


<div class="text-justify">



Hace unos días se publicó un post desde la cuenta de Aliento, hablando de la nueva App que he ayudado a desarrollar [Ver anuncio](https://peakd.com/hive-110011/@aliento/pjpawhbg#@aliento/re-liveofdalla-r9dw42), así desde la misma comunidad han surgido dudas de como hago para solicitar datos a la blockchain Hive mediante APIs y para no responder la duda de manera individual, me motivé hacer este post.


Para hacer requerimientos a la blockchain de una manera más común es mediante las APIs que integran a la plataforma, para ver todas las APIs puedes ingresar al siguiente link: 


<center>https://beacon.peakd.com/</center>


Allí dentro de esa página puedes ver las diferentes APIs, donde la más popular es https://api.hive.blog



#### ¿Qué necesito para extraer datos de Hive?


+ Conocimientos básicos en algún lenguaje de programación como Python o JavaScript
+ Instalar y explorar una librería de Hive correspondiente al lenguaje de programación que más domines, en mi caso uso [Beem](https://beem.readthedocs.io/en/latest/) para Python. 
+ Un editor de texto como [sublimetext](https://www.sublimetext.com/)



Estructura básica para extraer datos


```
### Extraer las propiedades básicas de la blockchain
from pprint import pprint
from beem import Hive
from beem.account import Account
from beem.instance import set_shared_blockchain_instance



hived_nodes = [

  'https://api.deathwing.me',
  'https://api.openhive.network',
]


hive = Hive(node=hived_nodes)


pprint(hive.get_chain_properties())


```


------ 

Resultado:

```
{'account_creation_fee': {'amount': '3000',
                          'nai': '@@000000021',
                          'precision': 3},
 'account_subsidy_budget': 797,
 'account_subsidy_decay': 347321,
 'hbd_interest_rate': 1200,
 'maximum_block_size': 65536}

```


Vamos a explorar la librería de Beem con un ejemplo: 

Lo primero que hacemos es ver como podemos extraer datos a partir de los módulos de Liberia mediante APIs [Ver](https://beem.readthedocs.io/en/latest/beem.account.html)


<center>![image.png](https://files.peakd.com/file/peakd-hive/enrique89/23tSz8K6WhzAF3ZymjePr6Q8zj5u1PPvdKf2j2Wu2Tb34ipZnac6gVAc5vuRiqZ1UJCQV.png)</center>

Para mostrar un ejemplo, voy a crear un código que me diga el balance de mi cuenta de Hive. 


Así está en la librería de Beem el módulo.

<center>![image.png](https://files.peakd.com/file/peakd-hive/enrique89/23y9KK8B12q5bdGi1wHBZV5zwhhtPytJAPsDwuZqEuwrb3o9QSGLVzX2NAWFSmg718HGe.png)</center>




Solo debemos agregar los siguientes códigos, para saber el balance de una cuenta de Hive: 


```
account = Account("enrique89", blockchain_instance= hive)

balance = account.get_balances()


pprint (balance)

```


Resultado: 


```
{'available': [731.184 HIVE, 27.270 HBD, 10243276.539006 VESTS],
 'rewards': [0.000 HIVE, 0.000 HBD, 994.817549 VESTS],
 'savings': [0.000 HIVE, 0.000 HBD],
 'total': [731.184 HIVE, 27.270 HBD, 10244271.356555 VESTS]}
[Finished in 2.4s]

```

Ahora vamos a probar con la reputación:



<center>![image.png](https://files.peakd.com/file/peakd-hive/enrique89/23twAQDSDynrzMt4uYPq6sSG28T9DUvnVxAGbvrMXisL3b1C1xcgSTJ6RidrFk43RVc53.png)</center>

Para solicitar la reputación agregamos el siguiente el código:

```
reputacion = account.get_reputation()


pprint (reputacion)


```
Resultado: 


```

75.2643870917311


```

Podemos interpretar que para solicitar información con la librería de Beem solo debemos sustituir el módulo. 

Hay algunas que tienen más variables como la siguiente: 


```
get_notifications(only_unread=True, limit=100, raw_data=False, account=None)

```

Probamos el módulo: 


get_notifications(only_unread=True, limit=100, raw_data=False, account=None)


Únicamente voy a modificar el limit y quitaré la variable account, con esta configuración me mostrará las no leídas.  


```
notificaciones = account.get_notifications(only_unread=True, limit=10, raw_data=False)


pprint (notificaciones)

```


Resultado: 



```
[{'date': datetime.datetime(2022, 4, 12, 0, 17, tzinfo=<UTC>),
  'id': 10217310,
  'msg': '@poshtoken mentioned you and 123 others',
  'score': 60,
  'type': 'mention',
  'url': '@poshtoken/posh-1649722618709'},
 {'date': datetime.datetime(2022, 4, 11, 16, 29, 42, tzinfo=<UTC>),
  'id': 10173683,
  'msg': '@hive-data mentioned you and 31 others',
  'score': 50,
  'type': 'mention',
  'url': '@hive-data/daily-twitter-data-reports-as-of-april-10-2022-2520-hive-tweets-of-the-day'},
 {'date': datetime.datetime(2022, 4, 10, 23, 15, 27, tzinfo=<UTC>),
  'id': 10095215,
  'msg': '@victoriabsb mentioned you and 68 others',
  'score': 60,
  'type': 'mention',
  'url': '@victoriabsb/hive-blockchain-la-guia-completa-para-nuevos-usuarios'},
 {'date': datetime.datetime(2022, 4, 10, 22, 43, 3, tzinfo=<UTC>),
  'id': 10092952,
  'msg': '@reylimarian replied to your post',
  'score': 40,
  'type': 'reply',
  'url': '@reylimarian/re-enrique89-ra5b3r'},
 {'date': datetime.datetime(2022, 4, 10, 22, 23, 39, tzinfo=<UTC>),
  'id': 10091467,
  'msg': '@dhenz voted on your post ($2.74)',
  'score': 75,
  'type': 'vote',
  'url': '@enrique89/es-momento-para-empezar-hive'},
 {'date': datetime.datetime(2022, 4, 10, 20, 28, 12, tzinfo=<UTC>),
  'id': 10080643,
  'msg': '@orinoco voted on your post ($0.28)',
  'score': 50,
  'type': 'vote',
  'url': '@enrique89/es-momento-para-empezar-hive'},
 {'date': datetime.datetime(2022, 4, 10, 20, 11, 57, tzinfo=<UTC>),
  'id': 10079481,
  'msg': '@ladyunicorn voted on your post ($0.02)',
  'score': 25,
  'type': 'vote',
  'url': '@enrique89/es-momento-para-empezar-hive'},
 {'date': datetime.datetime(2022, 4, 10, 18, 23, 6, tzinfo=<UTC>),
  'id': 10069980,
  'msg': '@grisvisa mentioned you and 0 others',
  'score': 60,
  'type': 'mention',
  'url': '@grisvisa/re-enrique89-ra4z2g'},
 {'date': datetime.datetime(2022, 4, 10, 18, 23, 6, tzinfo=<UTC>),
  'id': 10069979,
  'msg': '@grisvisa replied to your post',
  'score': 60,
  'type': 'reply',
  'url': '@grisvisa/re-enrique89-ra4z2g'},
 {'date': datetime.datetime(2022, 4, 10, 17, 49, 9, tzinfo=<UTC>),
  'id': 10067275,
  'msg': '@nahupuku replied to your comment',
  'score': 50,
  'type': 'reply_comment',
  'url': '@nahupuku/re-enrique89-ra4xhh'}]

```


Esto es parte de lo que puedes hacer con la Liberia de Beem conectada a la blockchain Hive, con esto ya  comenzar o pensar en hacer muchas aplicaciones y soluciones para estar conectados a los datos de esta gran blockchain. 



Estaré publicando este tipo de post, para animar a los desarrolladores que están en Hive a producir aplicaciones, bot y más, que estén conectados a Hive. 

Saludos.

</div>


<center>https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/enrique89/zLRXvucf-rect908.png</center>

<center> https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/enrique89/1wK1k8h4-rect4225.png </center>




👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 78 others
👎  
properties (23)
authorenrique89
permlinkhacer-consultas-a-la-blockchain-hive-mediante-apis-y-python
categoryhive-154226
json_metadata{"app":"peakd/2022.04.4","format":"markdown","tags":["spanish","web3","python","blockchain","hive"],"users":["aliento","000000021","poshtoken","hive-data","victoriabsb","reylimarian","dhenz","enrique89","orinoco","ladyunicorn"],"image":["https://files.peakd.com/file/peakd-hive/enrique89/23t76t9qhNjrg7wTwPXUDVNPkdko1Wfu7jjwdWBaKKEBcsLTitD4ekLGHvUAf66u8TaX6.png","https://files.peakd.com/file/peakd-hive/enrique89/23tSz8K6WhzAF3ZymjePr6Q8zj5u1PPvdKf2j2Wu2Tb34ipZnac6gVAc5vuRiqZ1UJCQV.png","https://files.peakd.com/file/peakd-hive/enrique89/23y9KK8B12q5bdGi1wHBZV5zwhhtPytJAPsDwuZqEuwrb3o9QSGLVzX2NAWFSmg718HGe.png","https://files.peakd.com/file/peakd-hive/enrique89/23twAQDSDynrzMt4uYPq6sSG28T9DUvnVxAGbvrMXisL3b1C1xcgSTJ6RidrFk43RVc53.png","https://files.peakd.com/file/peakd-hive/enrique89/zLRXvucf-rect908.png","https://files.peakd.com/file/peakd-hive/enrique89/1wK1k8h4-rect4225.png"]}
created2022-04-12 01:35:24
last_update2022-04-12 01:35:24
depth0
children4
last_payout2022-04-19 01:35:24
cashout_time1969-12-31 23:59:59
total_payout_value28.706 HBD
curator_payout_value28.927 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,052
author_reputation664,568,480,404,036
root_title"Hacer consultas a la blockchain Hive mediante APIs y Python"
beneficiaries
0.
accountdevelopspanish
weight100
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,216,048
net_rshares51,153,403,954,882
author_curate_reward""
vote details (143)
@hivebuzz ·
<center>[![](https://images.hive.blog/175x175/http://hivebuzz.me/@enrique89/level.png?202204130720)](https://hivebuzz.me/@enrique89)
<center>@enrique89, sorry to see you have less Hive Power.
Your level lowered and you are now a **Minnow**!</center>

**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202204-6"><img src="https://images.hive.blog/64x128/https://i.imgur.com/R438YeH.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202204-6">Hive Power Up Month - Feedback from April day 6</a></td></tr></table>

###### Support the HiveBuzz project. [Vote](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22199%22%5D&approve=true) for [our proposal](https://peakd.com/me/proposals/199)!
properties (22)
authorhivebuzz
permlinknotify-enrique89-20220413t073458
categoryhive-154226
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-04-13 07:34:57
last_update2022-04-13 07:34:57
depth1
children0
last_payout2022-04-20 07:34:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length755
author_reputation370,655,473,623,475
root_title"Hacer consultas a la blockchain Hive mediante APIs y Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,253,569
net_rshares0
@javivisan ·
Muchísimas gracias por tu post, soy un usuario con conocimientos básicos en Python pero es muy sencillo trabajar con las APIS para obtener datos. Ya me hice un bot en Telegram alojado en una Rasberry Pi que me envía información de mis cuentas de Splinterlands.
Espero seguir aprendiendo con estos tutoriales. Uno de como enviar automáticamente tokens de una cuenta a otra sería maravilloso.
¡Te felicito!
properties (22)
authorjavivisan
permlinkre-enrique89-ra809o
categoryhive-154226
json_metadata{"tags":["hive-154226"],"app":"peakd/2022.04.4"}
created2022-04-12 09:41:48
last_update2022-04-12 09:41:48
depth1
children0
last_payout2022-04-19 09:41:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length404
author_reputation278,634,217,465,295
root_title"Hacer consultas a la blockchain Hive mediante APIs y Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,224,697
net_rshares0
@poshtoken ·
https://twitter.com/enriquevee/status/1513937696292491266
<sub> The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
properties (22)
authorposhtoken
permlinkre-enrique89-hacer-consultas-a-la-blockchain-hive-mediante-apis-4564
categoryhive-154226
json_metadata"{"app":"Poshtoken 0.0.1"}"
created2022-04-12 18:11:27
last_update2022-04-12 18:11:27
depth1
children0
last_payout2022-04-19 18:11:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length245
author_reputation5,661,158,329,216,187
root_title"Hacer consultas a la blockchain Hive mediante APIs y Python"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id112,236,765
net_rshares0
@ragnarokreinier ·
Gracias por el post. No conocía esta comunidad ni esa librería para Python. Pronto estaré mostrando algunas cosillas interesantes que quiero hacer 🙃
properties (22)
authorragnarokreinier
permlinkre-enrique89-ra94tl
categoryhive-154226
json_metadata{"tags":["hive-154226"],"app":"peakd/2022.04.5"}
created2022-04-13 00:17:48
last_update2022-04-13 00:17:48
depth1
children0
last_payout2022-04-20 00:17:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length148
author_reputation1,142,478,689,879
root_title"Hacer consultas a la blockchain Hive mediante APIs y Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,245,421
net_rshares0