Interact with Bitcoin Blockchain directly using Python (Part 2)

in cryptocurrencies •  7 years ago 

In the Part 1 you can see how to install blockchain library in the python and query the last exchange prices. In this part, you will see how to explore blocks and transactions. first you need to import library:

from blockchain import blockexplorer as explorer

You can retrieve any desired block (e.g. genesisBlock):

genesisBlock = explorer.get_block('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')

There are some operation available on the block. as an example you can return height of block:

genesisBlock .height

Bitcoin_Block_Data.jpg
To retrieve transactions you can use following codes:

firstTransaction = explorer.get_tx('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b')


There are some operation available on the transaction. as an example you can return size of transaction:

firstTransaction.size

to retrieve new transactions (unconfirmed), you can use "get_unconfirmed_tx" function:

txs = explorer.get_unconfirmed_tx()

Also you can retrieve any wallet information using following codes (e.g. genesis wallet):

genesisAddress = be.get_address('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa')
genesisAddress.total_sent

We will see how to get blockchain statistical information in the next part.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!