1

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 = 
"7c7cd1c5f24b255ae113459dccdba8df3ff2e76ca0932d02f81be27311c64e32"

print "this is my private key: " + private_key

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

vk = sk.verifying_key

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

print "this is my public key: " + public_key

ripemd160 = hashlib.new('ripemd160')

ripemd160.update(hashlib.sha256(public_key.decode("hex")).digest())

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

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

checksum = 
hashlib.sha256(hashlib.sha256(middle_man).digest()).digest()[:4]

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.

0

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, privacy policy and cookie policy

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