<p>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 <a href="http://gobittest.appspot.com/Address" rel="nofollow noreferrer">private key here</a>, 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".</p>

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

CC BY-SA 3.0
2018-02-28T21:46:26.350Z
2018-02-28T21:46:26.350Z
pebwindkraft
<p>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.</p>

<pre><code>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
</code></pre>

<p>Update:
Finally i found a solution. It seems there was a problem in line</p>

<pre><code>middle_man = '\6f' + ripemd160.digest()
</code></pre>

<p>when importing raw bytes into a string</p>

<p>So I import struct and replaced the code above with:</p>

<pre><code>middle_man = struct.pack('=B',111) + ripemd160.digest()
</code></pre>

<p><a href="http://gobittest.appspot.com/Address" rel="nofollow noreferrer">http://gobittest.appspot.com/Address</a>  was really helpfull thanks.</p>

<bitcoin-core><blockchain><python>
Wrong testnet address generation [python]
S.Karoglou
# Wrong testnet address generation [python]

(Asked by: username_0 on 2018-02-27)

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.

**Tags:** bitcoin-core, blockchain, python


---

## 1 answers

### Answer by username_1 on 2018-02-28. Score: 0 | Accepted answer

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](http://gobittest.appspot.com/Address), 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.


---

