Posts

Showing posts with the label How to convert scriptPubKey bytes to Bitcoin address?

How to convert scriptPubKey bytes to Bitcoin address?

How to convert scriptPubKey bytes to Bitcoin address? I am currently trying myself in parsing the blockchain using pyblockchain . My problem is that I am not able to encode the scriptPubKey correctly - although I don't know what I could possibly do wrong. Below you can see how I traverse the blockchain: from blockchain.reader import BlockchainFileReader import hashlib import base58 block_reader = BlockchainFileReader('/media/Data/btc/blocks/blk00325.dat') count = 0 for block in block_reader: count +=1 for t in block.transactions: for outp in t.outputs: addr = base58.b58encode(outp.script_pub_key) if addr.startswith('1'): print(addr) if count >= 5: break If I, in my Jupyter notebook, take a look at outp, I'll find for outp.script_pub_key >> b'v\xa9\x14\x1e\xbev\x83\xceJd\xad\xc9\x17\xe9\xb1\x93\x7f\x12&Q\xcb\xab\xa1\x88\xac' this: base58.b58en...