<p>Some observations: the priv key matches with the first compressed address (mkhn3...). It fits to the pubkey in hex, see below. 
The way keys are derived is described here - see also the picture.
<a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html</a></p>

<p><a href="https://i.sstatic.net/Uw5oB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Uw5oB.png" alt="enter image description here"></a></p>

<p>Once you have the pubkey in hex, there are 8 following steps to come to the final bitcoin address:</p>

<pre><code>1 - Public ECDSA Key
2 - SHA-256 hash of 1
3 - RIPEMD-160 Hash of 2
4 - Adding network bytes to 3
5 - SHA-256 hash of 4
6 - SHA-256 hash of 5
7 - First four bytes of 6
8 - Adding 7 at the end of 4
9 - Base58 encoding of 8
</code></pre>

<p>The first <strong>uncompressed</strong> pubkey (which fits to the privkey):</p>

<blockquote>
  <p>042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583</p>
</blockquote>

<p>would convert into this bitcoin address: </p>

<pre><code>myfp2YcyYjksxmdfA74yEuBmaUgt9xWCot
</code></pre>

<p>and your second <strong>uncompressed</strong> pubkey</p>

<blockquote>
  <p>040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b</p>
</blockquote>

<p>would convert to this bitcoin address:</p>

<pre><code>mmKUwoRgd9YdvRYYXGyumjduRMTAPCnkMz
</code></pre>

<p>I am not sure which tools you used to create your keys, it looks like you have somewhere a gap between using <strong>compressed</strong> and <strong>uncompressed</strong> keys. 
A very good reference is in the online book from Andreas ("Mastering Bitcoin, 2nd edition"), which is also online readable (see chapter 4...).</p>

CC BY-SA 3.0
2018-01-02T11:02:07.633Z
Thank you for your responses, you've been very helpful with my questions. I will look into the online book hoping it will provide me better understanding. However, following the procedures you mentioned (which is what I've been doing so far), generates a single pubkey, what is the process for generating the second one?
user2298995
CC BY-SA 3.0
2018-01-02T12:36:33.103Z
Now I got it, seems like I misunderstood your point. How can an uncompressed pubkey and a compressed pubkey result in the same public address?
user2298995
CC BY-SA 3.0
2018-01-02T14:28:52.150Z
compressed and uncompressed pubkeys never result in the same address. The root is the hex private key (64 hexadecimal digits). From this you can create a WIF encoded key, and depending on the prefix, you get a key starting with "5", or with "L" or "K". The process is well described in Andreas' book. When creating the pubkeys, there are  uncompressed pubkeys for WIF keys starting with "5", the others would create  compressed pubkeys.
pebwindkraft
CC BY-SA 3.0
2018-01-02T14:31:50.067Z
Summary: with the same private key you can create compressed or uncompressed WIF keys (a representation of hex keys), and from there create the two pubkeys, which can be converted into two different bitcoin addresses. Though both addresses (and keys) are based on the same priv key, they are not "interchangeable". In Bitcoin they lead to  completly different addresses.
pebwindkraft
CC BY-SA 3.0
2018-01-02T09:57:04.060Z
2018-01-02T09:57:04.060Z
pebwindkraft
<p>I'm trying to create a transaction on the testnet (manually). I have the following private key: <code>cQKqSNkEdyLJziQSr4iKTUJC95s9HHFo4bY88gi2i6v2quiVVLZb</code> which belongs to the following public address: <code>mkhn3gfrGHmd4b1ZmHLdMsbQd2eHRKg8wN</code>. When I try to sign the transaction, the public (uncompressed) key that I generate, is: <code>042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583</code>. This turns out to be invalid (because the transaction gets rejected by the network). However, when I tried using a tool for signing the transaction, it generated the following (correct) public key: <code>040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b</code>.</p>

<p>What is the difference between these keys? How come the first one is incorrect when signing the tx but correct when I generated the public address for it?</p>

<testnet>
Public key for testnet address
user2298995
# Public key for testnet address

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

I'm trying to create a transaction on the testnet (manually). I have the following private key: `cQKqSNkEdyLJziQSr4iKTUJC95s9HHFo4bY88gi2i6v2quiVVLZb` which belongs to the following public address: `mkhn3gfrGHmd4b1ZmHLdMsbQd2eHRKg8wN`. When I try to sign the transaction, the public (uncompressed) key that I generate, is: `042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583`. This turns out to be invalid (because the transaction gets rejected by the network). However, when I tried using a tool for signing the transaction, it generated the following (correct) public key: `040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b`.

What is the difference between these keys? How come the first one is incorrect when signing the tx but correct when I generated the public address for it?

**Tags:** testnet


---

## 1 answers

### Answer by username_1 on 2018-01-02. Score: 3 | Accepted answer

Some observations: the priv key matches with the first compressed address (mkhn3...). It fits to the pubkey in hex, see below.
The way keys are derived is described here - see also the picture.
<http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html>

[![enter image description here](https://i.sstatic.net/Uw5oB.png)](https://i.sstatic.net/Uw5oB.png)

Once you have the pubkey in hex, there are 8 following steps to come to the final bitcoin address:

```
1 - Public ECDSA Key
2 - SHA-256 hash of 1
3 - RIPEMD-160 Hash of 2
4 - Adding network bytes to 3
5 - SHA-256 hash of 4
6 - SHA-256 hash of 5
7 - First four bytes of 6
8 - Adding 7 at the end of 4
9 - Base58 encoding of 8

```

The first **uncompressed** pubkey (which fits to the privkey):

> 042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583

would convert into this bitcoin address:

```
myfp2YcyYjksxmdfA74yEuBmaUgt9xWCot

```

and your second **uncompressed** pubkey

> 040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b

would convert to this bitcoin address:

```
mmKUwoRgd9YdvRYYXGyumjduRMTAPCnkMz

```

I am not sure which tools you used to create your keys, it looks like you have somewhere a gap between using **compressed** and **uncompressed** keys.
A very good reference is in the online book from Andreas ("Mastering Bitcoin, 2nd edition"), which is also online readable (see chapter 4...).

> **Comments:**
> **username_0**: Thank you for your responses, you've been very helpful with my questions. I will look into the online book hoping it will provide me better understanding. However, following the procedures you mentioned (which is what I've been doing so far), generates a single pubkey, what is the process for generating the second one?  
> **username_0**: Now I got it, seems like I misunderstood your point. How can an uncompressed pubkey and a compressed pubkey result in the same public address?  
> **username_1**: compressed and uncompressed pubkeys never result in the same address. The root is the hex private key (64 hexadecimal digits). From this you can create a WIF encoded key, and depending on the prefix, you get a key starting with "5", or with "L" or "K". The process is well described in Andreas' book. When creating the pubkeys, there are  uncompressed pubkeys for WIF keys starting with "5", the others would create  compressed pubkeys.  
> **username_1**: Summary: with the same private key you can create compressed or uncompressed WIF keys (a representation of hex keys), and from there create the two pubkeys, which can be converted into two different bitcoin addresses. Though both addresses (and keys) are based on the same priv key, they are not "interchangeable". In Bitcoin they lead to  completly different addresses.  

---

