Block explorer methods

For block explorer methods, start by importing the relevant classes from the blockchain library. To get a particular block, call the get_block method as shown in the following code. It expects a block to be passed in as the parameter.

# import blockchain library
from blockchain import blockexplorer

# get a particular block
block = blockexplorer.get_block('')

By taking an example block from the web, from Blockchain.info, copy the hash for this block (Block #536081) and pass it to the get_block method, as shown in the following screenshot:

Now lets get some information about this block. For example, the block fee, block size, and block transactions can be obtained by using fee, size, and transactions properties respectively on the block object created, as shown in the following code:

#!/usr/bin/env python

# import blockchain library
from blockchain import blockexplorer

# get a particular block
block = blockexplorer.get_block('0000000000000000002e90b284607359f3415647626447643b9b880ee00e41fa')

print("Block Fee: %s " % block.fee)
print("Block size: %s " % block.size)
print("Block transactions: %s " % block.transactions)

# get the latest block
block = blockexplorer.get_latest_block()

The following screenshot shows the block fee, block size, and block transactions output:

There are also many available features in the Blockchain.info library; there are a few that are more related to, for example, wallets, creating wallets, and so on.

In order to explore this library further, visit the link https://github.com/blockchain/api-v1-client-python.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.18.141