I'm trying to generate a testnet address without success.Main net address is working fine. Here is my code. The generated testnet address from this code is :CNFNz61dzQ2NQ9RCnjJFrm2de7nLbbT9xSv which is in wrong format.

import os
import ecdsa
import hashlib
import base58

#private_key = os.urandom(32).encode("hex")
private_key = 

print "this is my private key: " + private_key

sk = ecdsa.SigningKey.from_string(private_key.decode("hex"), curve = 

vk = sk.verifying_key

public_key = ('\04'+ vk.to_string()).encode("hex")

print "this is my public key: " + public_key

ripemd160 = hashlib.new('ripemd160')


#main network id
#middle_man = '\00' + ripemd160.digest()

#testnet id
middle_man = '\6f' + ripemd160.digest()

checksum = 

binary_addr = middle_man + checksum

addr = base58.b58encode(binary_addr)

# main address = 19kyG9Q5QXMEZSpte6fpTeo1BWKV5Pa6ch
print "testnet address: " + addr

Update: Finally i found a solution. It seems there was a problem in line

middle_man = '\6f' + ripemd160.digest()

when importing raw bytes into a string

So I import struct and replaced the code above with:

middle_man = struct.pack('=B',111) + ripemd160.digest()

http://gobittest.appspot.com/Address was really helpfull thanks.

1 Answer 1


You didn't post the wrong result that you get... As I am not a python specialist, and don't know the library calls, I have an idea: you may want to place your private key here, and add print(s) after every step as debug commands, and compare line by line. I just checked the privkey and the pubkey, the page returns the same result as your main address. If you enter in step 4 the "6f", you get this testnet address: "mpGvZCV4DYnVLZJWMfeCHa1L3VvC1hetT8".

When done, you can edit your question and show how you fixed it, or extend the question with your results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.