How to generate unspendable testnet bitcoin address with python?

I’m trying to generate a testnet address. However, I tried to write this python program (using help of various online code places), and I created this program. The program is designed to take a 20 byte input and then turn that 20 bytes of data into an address by putting the version byte (6f), the meat of the data (the 20 bytes being added into the code), and the checksum. However, it didn’t work.

# *-* encoding: utf-8 *-*

import hashlib, codecs, sys, base58, bytes, base64
def checksum(inPut):
# Double SHA256 to get checksum
sha256_nbpk = hashlib.sha256(inPut.encode())
sha256_nbpk_digest = sha256_nbpk.digest()
sha256_2_nbpk = hashlib.sha256(sha256_nbpk_digest)
sha256_2_nbpk_digest = sha256_2_nbpk.digest()
sha256_2_hex = codecs.encode(sha256_2_nbpk_digest, 'hex')
return (str(sha256_2_hex)[2:-1])[:8]

x = "6f"+"64"*20
x += checksum(x)
print(str(base58.b58encode(str(base64.b16decode(x.upper()))))[2:-1])

Source link

Leave a Comment

Your email address will not be published.