A python 3 api-wrapper for https://blockstream.info bitcoin blockchain explorer
Any of the following will work.
If In a python3 virtual environment use:
pip install blockstream
Otherwise use one of the following
pip3 install blockstream
python3 -m pip install blockstream
from blockstream import blockexplorer
There is nothing formal in the documentation but this works
sleep_time = .25 # don't overstep rate limits
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#transactions
Example JSON response for transaction: https://blockstream.info/api/tx/546681da510fcdd4b6712b96a791ca5084005f7276f235767c28f91ef0141c9e
+ id: str
+ version: int
+ locktime: int
+ vin: list
+ vout: list
+ size: int
+ weight: int
+ fee: int
+ status: dict
Returns an instance of Transaction
class
tx_id = '73236c12b8595c85dc629e1e01e4a0938376fb6c219632a97429ab59d6c0fac3'
transaction = blockexplorer.get_transaction(tx_id)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-txtxidstatus
+ confirmed
+ block_height
+ block_hash
+ block_time
Returns an instance of TransactionStatus
class
tx_id = '73236c12b8595c85dc629e1e01e4a0938376fb6c219632a97429ab59d6c0fac3'
tx_status = blockexplorer.get_transaction_status(tx_id)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-txtxidhex
Returns a string
tx_id = '73236c12b8595c85dc629e1e01e4a0938376fb6c219632a97429ab59d6c0fac3'
tx_hex = blockexplorer.get_transaction_hex(tx_id)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-txtxidmerkle-proof
+ block_height
+ merkle
+ pos
Returns an instance of TransactionMerkleProof
class
tx_merkle_proof = blockexplorer.get_transaction_merkle_proof(tx_id)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-txtxidoutspendvout
+ spend
+ tx_id
+ vin
+ status
Returns an instance of TransactionOutput
class
vout = '1B2fFAimxLTDgvtLPs212pa3f7ymHdVQmV'
tx_output_status = blockexplorer.get_transaction_output_status(tx_id, vout)
Returns a list of TransactionOutput
objects
all_outspends = blockexplorer.get_all_transaction_outputs_statuses(tx_id)
# not added yet
Example JSON response for Address: https://blockstream.info/api/address/3ADPkym6mQ2HyP7uASh5g3VYauhCWZpczF
+ address: str
+ chain_stats: dict
+ mempool_stats: dict
Get information about an address
Returns an instance of Address
class
address = 'bc1qw6lwxz3lxtg969hx7g0qnxfnm7608m3nxu7far'
addr_info = blockexplorer.get_address(address)
Get transactions that an address has taken part in
Returns a list of Transaction
objects
txs = blockexplorer.get_address_transactions(address)
Returns a list of Transaction
objects
confirmed_tx_hist = blockexplorer.get_confirmed_transaction_history(address)
addr_mempool = blockexplorer.get_address_mempool(address)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-addressaddressutxo
Example JSON Response: https://blockstream.info/api/address/3ADPkym6mQ2HyP7uASh5g3VYauhCWZpczF/utxo
+ tx_id: str
+ vout: int
+ status: dict
+ value: int
Returns an instance of UTXO
class
addr_utxo = blockexplorer.get_address_utxo(address)
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#mempool
Example JSON response: https://blockstream.info/api/mempool
+ count
+ vsize
+ total_fee
+ fee_histogram
Returns an instance of Mempool
class
mempool = blockexplorer.get_mempool()
Returns a list of of type str
(Transaction hashes/IDs)
mempool_tx_ids = blockexplorer.get_mempool_transaction_ids()
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-mempoolrecent
Example JSON Response: https://blockstream.info/api/mempool/recent
+ tx_id: str
+ fee: int
+ vsize: int
+ value: int
Returns an instance of MempoolRecent
class
recent_mempool_txs = blockexplorer.get_mempool_transaction_ids()
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#fee-estimates
Example JSON Response: https://blockstream.info/api/fee-estimates
+ two_blocks: float
+ three_blocks: float
+ four_blocks: float
+ six_blocks: float
+ ten_blocks: float
+ twenty_blocks: float
+ onefourfour_blocks: float
+ fivezerofour_blocks: float
+ tenzeroeight_blocks: float
Returns an instance of FeeEstimates
class
fee_estimates = blockexplorer.get_fee_estimates()
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#blocks
Example JSON Response: https://blockstream.info/api/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
Returns a block hash. Return type: str
block_hash = blockexplorer.get_block_hash_from_height('575165')
+ id: str
+ height: int
+ version: int
+ timestamp: int
+ tx_count: int
+ size: int
+ weight: int
+ merkle_root: str
+ previous_block_hash: str
+ nonce: int
+ bits: int
Returns an instance of Block
Class
block_hash = '0000000000000000000cf9b9dd7bb882d825f4e3830dc9391425c40c56e82d7f'
block = blockexplorer.get_block_by_hash(block_hash)
Returns an instance of Block
Class
block = blockexplorer.get_block_by_height('575165')
API Docs: https://github.com/Blockstream/esplora/blob/master/API.md#get-blockhashstatus
Example JSON response: https://blockstream.info/api/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f/status
+ in_best_chain: boolean
+ height: int
+ next_best: str
Returns an intance of BlockStatus
class
block_status = blockexplorer.get_block_status(block_hash)
Get a list of transactions in a specific block
Returns a list of Transaction
objects
transactions = blockexplorer.get_block_transactions(block_hash)
Get a list of transaction hashes/IDs
Returns a list of type: str
txids = blockexplorer.get_transaction_ids(block_hash)
Returns a list of Block
objects
recents = blockexplorer.get_blocks()
Returns a list of Block
objects
height_of_interest = '575135'
ten_blocks = blockexplorer.get_blocks(height_of_interest)
Get the most recent block height
Return type: int
tip_height = blockexplorer.get_last_block_height()
Get the most recent block hash
Return type: str
tip_hash = blockexplorer.get_last_block_hash()