<p>First, note that the scriptSig on the genesis block was before addresses were used. The scriptSig there is called p2pk, or pay-to-pub-key. Addresses (the kind starting with a 1) are actually p2pkh, or pay-to-pub-key-hash. You can convert one to the other fairly easily and that's what's going on here.</p>

<p>The actual scriptSig can be parsed like so:</p>

<pre><code>41 = number of bytes in hex of the element (65 bytes)
04...5f = public key
ac = OP_CHECKSIG
</code></pre>

<p>Plug in 04...5f into the Public ECDSA key at <a href="http://gobittest.appspot.com/Address" rel="nofollow">http://gobittest.appspot.com/Address</a> and you'll see that the address does indeed match.</p>

CC BY-SA 3.0
2016-05-30T06:08:03.760Z
My fault was, that I took the first and last byte also as part of the pub-key. when I removed it, everything was correct
Erhard Dinhobl
CC BY-SA 3.0
2016-06-10T06:16:36.877Z
But how to convert all the others to an address (beside those in the genesis block)? like: 76a91487bfdc1e986af9671805a902e0b2ca853f587d6288ac
Erhard Dinhobl
CC BY-SA 3.0
2016-06-10T20:07:05.207Z
Take out the 76a914 at the beginning (OP_DUP, OP_HASH160, 20 byte length) and the 88ac at the end (OP_EQUALVERIFY, OP_CHECKSIG) and put that into box 3.
Jimmy Song
CC BY-SA 3.0
2016-06-13T12:23:24.947Z
Thanks I will try it! But is there a general approache for that? Because I have some other scripts and I think asking for every case would lead to a huge blowup.....
Erhard Dinhobl
CC BY-SA 3.0
2016-06-13T13:01:31.533Z
Should I interpret the script and take the stack?
Erhard Dinhobl
CC BY-SA 3.0
2016-06-13T15:04:26.300Z
because "a9149cb09d17e24e9b985a4efccf44ee4debce48ef0b87" is another problem and I tried many paddings left and right
Erhard Dinhobl
CC BY-SA 3.0
2016-06-19T02:17:23.033Z
The way to get this generally is to take the binary and make it into script form. OP_HASH160 <hash> OP_EQUAL seems to be the form, so if you take out the a914 at the front and 87 at the end, you'll have the hash160 (box 3). Note this means there needs to be no signature, so it's a very dangerous script that shouldn't get used.
Jimmy Song
CC BY-SA 3.0
2016-07-25T11:05:27.330Z
Ok,. I take

Transaction e99783084c44b670c8206c8b3071878963bcf691812005bb416666ba1f500301

At out1 script sig is: a914564960b6d6eb2d10e4580b1441fd69793a184c0287 

and then based on walletexplorer.com, the

address there should be: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM

So I take "a914" (begin) and "87" (end) away.

Remaining script sig: 564960b6d6eb2d10e4580b1441fd69793a184c02

Now i tried this in every box on the site http://gobittest.appspot.com/Address but I never got the address: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM.
Erhard Dinhobl
CC BY-SA 3.0
2016-07-25T11:15:22.190Z
Maybe someone else has some information.
Erhard Dinhobl
CC BY-SA 3.0
2016-05-27T17:19:39.223Z
2016-05-27T17:19:39.223Z
Jimmy Song
<p>Or maybe am I right with the following assumptions:
there are three types of scriptSig's</p>

<ol>
<li>OP_DUP OP_HASH160 .... OP_EQUALVERIFY OP_CHECKSIG</li>
<li>OP_HASH160 ... OP_EQUAL</li>
<li>OP_m ... OP_CHECKMULTISIG</li>
</ol>

<p>But what to do now with these options? In the 3rd option I only have to take all bytes represented as "..." and decode it. But whats with the others?</p>

<p>E.g.: hot to get it from: 76a91490bb78d00b26139e4d51ceb9655295c2bd98aed688ac</p>

CC BY-SA 3.0
2016-06-10T07:00:48.440Z
2016-06-13T12:34:25.123Z
2016-06-13T12:34:25.123Z
Erhard Dinhobl
<p>I know that getting the address from the <code>blk*.dat</code> files is discussed a lot of times. But I don't get it why? When I have the raw scriptSig I can encode it and get the bitcoin address or not?</p>

<p>E.g. the first block the first transation:</p>

<p>input scriptSig (this value is correct, as defined here: <a href="https://en.bitcoin.it/wiki/Genesis_block" rel="nofollow">https://en.bitcoin.it/wiki/Genesis_block</a>):</p>

<pre><code>04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73
</code></pre>

<p>output scriptSig:</p>

<pre><code>4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac
</code></pre>

<p>as written in here: <a href="https://en.bitcoin.it/wiki/Genesis_block" rel="nofollow">https://en.bitcoin.it/wiki/Genesis_block</a>
the address of the output is: </p>

<pre><code>1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
</code></pre>

<p>now, how to get from the scriptSig <code>4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac</code> to the address <code>1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa</code>?</p>

<p>If you try it here: <a href="http://gobittest.appspot.com/Address" rel="nofollow">http://gobittest.appspot.com/Address</a> the output is NOT the expected address "1A1....."</p>

<transactions><blockchain><address><python><block-header>
getting bitcoin address of blk*.dat files
Erhard Dinhobl
# getting bitcoin address of blk*.dat files

(Asked by: username_0 on 2016-05-27)

I know that getting the address from the `blk*.dat` files is discussed a lot of times. But I don't get it why? When I have the raw scriptSig I can encode it and get the bitcoin address or not?

E.g. the first block the first transation:

input scriptSig (this value is correct, as defined here: <https://en.bitcoin.it/wiki/Genesis_block>):

```
04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73

```

output scriptSig:

```
4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

```

as written in here: <https://en.bitcoin.it/wiki/Genesis_block>
the address of the output is:

```
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

```

now, how to get from the scriptSig `4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac` to the address `1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa`?

If you try it here: <http://gobittest.appspot.com/Address> the output is NOT the expected address "1A1....."

**Tags:** transactions, blockchain, address, python, block-header


---

## 2 answers

### Answer by username_1 on 2016-05-27. Score: 2

First, note that the scriptSig on the genesis block was before addresses were used. The scriptSig there is called p2pk, or pay-to-pub-key. Addresses (the kind starting with a 1) are actually p2pkh, or pay-to-pub-key-hash. You can convert one to the other fairly easily and that's what's going on here.

The actual scriptSig can be parsed like so:

```
41 = number of bytes in hex of the element (65 bytes)
04...5f = public key
ac = OP_CHECKSIG

```

Plug in 04...5f into the Public ECDSA key at <http://gobittest.appspot.com/Address> and you'll see that the address does indeed match.

> **Comments:**
> **username_0**: My fault was, that I took the first and last byte also as part of the pub-key. when I removed it, everything was correct  
> **username_0**: But how to convert all the others to an address (beside those in the genesis block)? like: 76a91487bfdc1e986af9671805a902e0b2ca853f587d6288ac  
> **username_1**: Take out the 76a914 at the beginning (OP_DUP, OP_HASH160, 20 byte length) and the 88ac at the end (OP_EQUALVERIFY, OP_CHECKSIG) and put that into box 3.  
> **username_0**: Thanks I will try it! But is there a general approache for that? Because I have some other scripts and I think asking for every case would lead to a huge blowup.....  
> **username_0**: Should I interpret the script and take the stack?  
> **username_0**: because "a9149cb09d17e24e9b985a4efccf44ee4debce48ef0b87" is another problem and I tried many paddings left and right  
> **username_1**: The way to get this generally is to take the binary and make it into script form. OP_HASH160 <hash> OP_EQUAL seems to be the form, so if you take out the a914 at the front and 87 at the end, you'll have the hash160 (box 3). Note this means there needs to be no signature, so it's a very dangerous script that shouldn't get used.  
> **username_0**: Ok,. I take  Transaction e99783084c44b670c8206c8b3071878963bcf691812005bb416666ba1f500301  At out1 script sig is: a914564960b6d6eb2d10e4580b1441fd69793a184c0287   and then based on walletexplorer.com, the  address there should be: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM  So I take "a914" (begin) and "87" (end) away.  Remaining script sig: 564960b6d6eb2d10e4580b1441fd69793a184c02  Now i tried this in every box on the site http://gobittest.appspot.com/Address but I never got the address: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM.  
> **username_0**: Maybe someone else has some information.  

---

### Answer by username_0 on 2016-06-10. Score: 0

Or maybe am I right with the following assumptions:
there are three types of scriptSig's

1. OP\_DUP OP\_HASH160 .... OP\_EQUALVERIFY OP\_CHECKSIG
2. OP\_HASH160 ... OP\_EQUAL
3. OP\_m ... OP\_CHECKMULTISIG

But what to do now with these options? In the 3rd option I only have to take all bytes represented as "..." and decode it. But whats with the others?

E.g.: hot to get it from: 76a91490bb78d00b26139e4d51ceb9655295c2bd98aed688ac


---

