<blockquote>
<p>In raw transaction, bitcoin using bytes of the public key, like:
042daa93315eebbe2cb9b5c3505df4c6fb6caca8b756786098567550d4820c09db988fe9997d049d687292f815ccd6e7fb5c1b1a91137999818d17c73d0f80aef9</p>
</blockquote>
<p>Technically the raw transaction contains the Script, which usually is written with Bitcoin script that is a stack-based language. It can contain the PubKey in the old scripts, like P2PK but the community is making a big effort to move the bitcoin users to use the script that contains the hash of the public key. The script like Pay-to-Public-Key-Hash (P2PKH) or pay-to-witness-public-key-hash (P2WPKH).</p>
<p>from the script, it is possible to calculate the address but not vice versa.</p>
<p>In conclusion, all the addresses have a conversion like:</p>
<ul>
<li><strong>P2PK, P2PKH</strong>: Start with 1.</li>
<li><strong>P2SH</strong>: start with 3.</li>
<li><strong>P2WSH, P2WPKH</strong>: Start with bc or with 3.</li>
</ul>
<p>At this point, the answer should contain a resume of all the types of script and how the script is built, and also an introduction to the not standard script that is used extensively from the lightning network protocol.</p>
<p>But I think a very good summary is inside these two chapters of the Bitcoin book <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch06.asciidoc" rel="nofollow noreferrer">'Transactions'</a> and <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc" rel="nofollow noreferrer">'Advanced Transactions and Scripting'</a>, I can't do better</p>
<h2>Update</h2>
<p>I'm not a fan of theory, maybe you can use also this code example to understand how the script is converted on a Bitcoin address.
<a href="https://github.com/vincenzopalazzo/decompiler-bitcoin-script/blob/master/src/main.cpp" rel="nofollow noreferrer">Decompiler Bitcoin Script</a>.</p>
<p>it is only an example of the conversion that could be done.</p>
<p>The usage of the example code is described inside the bash script <a href="https://github.com/vincenzopalazzo/decompiler-bitcoin-script/blob/master/run-decompiler.sh" rel="nofollow noreferrer">run-decompiler.sh</a></p>
<p>An example with the <a href="https://blockstream.info/tx/54ae4952a8501fe11096f455745168c74d656f94c6bf31d1063d9728f478eea5" rel="nofollow noreferrer">following block</a> is the following <code>./Decompiler 76a914536ffa992491508dca0354e52f32a3a7a679a53a88ac</code></p>
<p>With the following result</p>
<pre><code>----------------------------------------| Results |-----------------------------------
                               ###  Script PAY TO PUBLIC KEY HASH  ###                            
  Raw Script PubKey: 76a914536ffa992491508dca0354e52f32a3a7a679a53a88ac

OP_DUP OP_HASH160 536ffa992491508dca0354e52f32a3a7a679a53a OP_EQUALVERIFY OP_CHECKSIG
                                                                                      
 The address: 18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX
 The Hash160 pubkey: 536ffa992491508dca0354e52f32a3a7a679a53a
 The P2PSH address: 39JC9tvQ5CANbfuPgUZ4Zdc227m5uQnMRB

 https://blockstream.info/address/18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX
______________________________________________________________________________________
</code></pre>
<p>See the result here <a href="https://blockstream.info/address/18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX" rel="nofollow noreferrer">https://blockstream.info/address/18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX</a></p>
<p>Please consider this example as an example of code, I developed this to understand how de script works. Can contains error. I will work to integrate this in my project and I will maintain this post update.</p>
<p>To answer at your comment that is</p>
<blockquote>
<p>Thanks. I use you the code linked, the the result address codepad.org/nRJhvMC3 does not match the expected address blockchain.com/btc/block/1 So what's the usage of this Decompiler?</p>
</blockquote>
<p>The decompiler takes the <code>hex</code> of the script and try to calculate the corresponding address if it is a standard script.</p>

CC BY-SA 4.0
2021-02-28T12:32:45.870Z
Thanks. I use you the code linked, the the result address http://codepad.org/nRJhvMC3 does not match the expected address https://www.blockchain.com/btc/block/1 So what's the usage of this `Decompiler`?
ntk138
CC BY-SA 4.0
2021-02-28T13:22:00.817Z
Oh, I see, interesting, I have some bug in the P2PK deserialization, sorry you have right.  I will fix it for the P2PK. if you run the script you have a complete summary where is contained the link to see the address information on an explorer. Sorry for the P2PK deserialization. I update the post with an example of how to use the code
vincenzopalazzo
CC BY-SA 4.0
2021-02-28T13:28:16.767Z
I fixed the bug with this commit https://github.com/vincenzopalazzo/decompiler-bitcoin-script/commit/b5540532f2e15e867be44573af4617711db96f31  thanks so much and sorry, now you can see with the following command that you address if calculate the same `./Decompiler 410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac`. Look here the result https://blockstream.info/address/12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX
vincenzopalazzo
CC BY-SA 4.0
2021-02-28T10:35:58.747Z
2021-05-15T23:23:59.537Z
2021-05-15T23:23:59.537Z
vincenzopalazzo
<p>In raw transaction, bitcoin using bytes of the public key, like:</p>
<pre><code>042daa93315eebbe2cb9b5c3505df4c6fb6caca8b756786098567550d4820c09db988fe9997d049d687292f815ccd6e7fb5c1b1a91137999818d17c73d0f80aef9
</code></pre>
<p>It takes a lot of bytes.</p>
<p>Technically, can we use bitcoin addresses (e.g.<code>1MBngSqZbMydscpzSoehjP8kznMaHAzh9y </code>) instead to make the blocks smaller?</p>

<raw-transaction>
Why not use address in raw transaction instead of public key bytes
ntk138
# Why not use address in raw transaction instead of public key bytes

(Asked by: username_0 on 2021-02-28)

In raw transaction, bitcoin using bytes of the public key, like:

```
042daa93315eebbe2cb9b5c3505df4c6fb6caca8b756786098567550d4820c09db988fe9997d049d687292f815ccd6e7fb5c1b1a91137999818d17c73d0f80aef9

```

It takes a lot of bytes.

Technically, can we use bitcoin addresses (e.g.`1MBngSqZbMydscpzSoehjP8kznMaHAzh9y` ) instead to make the blocks smaller?

**Tags:** raw-transaction


---

## 1 answers

### Answer by username_1 on 2021-02-28. Score: 3 | Accepted answer

> In raw transaction, bitcoin using bytes of the public key, like:
> 042daa93315eebbe2cb9b5c3505df4c6fb6caca8b756786098567550d4820c09db988fe9997d049d687292f815ccd6e7fb5c1b1a91137999818d17c73d0f80aef9

Technically the raw transaction contains the Script, which usually is written with Bitcoin script that is a stack-based language. It can contain the PubKey in the old scripts, like P2PK but the community is making a big effort to move the bitcoin users to use the script that contains the hash of the public key. The script like Pay-to-Public-Key-Hash (P2PKH) or pay-to-witness-public-key-hash (P2WPKH).

from the script, it is possible to calculate the address but not vice versa.

In conclusion, all the addresses have a conversion like:

* **P2PK, P2PKH**: Start with 1.
* **P2SH**: start with 3.
* **P2WSH, P2WPKH**: Start with bc or with 3.

At this point, the answer should contain a resume of all the types of script and how the script is built, and also an introduction to the not standard script that is used extensively from the lightning network protocol.

But I think a very good summary is inside these two chapters of the Bitcoin book ['Transactions'](https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch06.asciidoc) and ['Advanced Transactions and Scripting'](https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc), I can't do better

## Update

I'm not a fan of theory, maybe you can use also this code example to understand how the script is converted on a Bitcoin address.
[Decompiler Bitcoin Script](https://github.com/username_1/decompiler-bitcoin-script/blob/master/src/main.cpp).

it is only an example of the conversion that could be done.

The usage of the example code is described inside the bash script [run-decompiler.sh](https://github.com/username_1/decompiler-bitcoin-script/blob/master/run-decompiler.sh)

An example with the [following block](https://blockstream.info/tx/54ae4952a8501fe11096f455745168c74d656f94c6bf31d1063d9728f478eea5) is the following `./Decompiler 76a914536ffa992491508dca0354e52f32a3a7a679a53a88ac`

With the following result

```
----------------------------------------| Results |-----------------------------------
                               ###  Script PAY TO PUBLIC KEY HASH  ###                            
  Raw Script PubKey: 76a914536ffa992491508dca0354e52f32a3a7a679a53a88ac

OP_DUP OP_HASH160 536ffa992491508dca0354e52f32a3a7a679a53a OP_EQUALVERIFY OP_CHECKSIG
                                                                                      
 The address: 18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX
 The Hash160 pubkey: 536ffa992491508dca0354e52f32a3a7a679a53a
 The P2PSH address: 39JC9tvQ5CANbfuPgUZ4Zdc227m5uQnMRB

 https://blockstream.info/address/18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX
______________________________________________________________________________________

```

See the result here <https://blockstream.info/address/18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX>

Please consider this example as an example of code, I developed this to understand how de script works. Can contains error. I will work to integrate this in my project and I will maintain this post update.

To answer at your comment that is

> Thanks. I use you the code linked, the the result address codepad.org/nRJhvMC3 does not match the expected address blockchain.com/btc/block/1 So what's the usage of this Decompiler?

The decompiler takes the `hex` of the script and try to calculate the corresponding address if it is a standard script.

> **Comments:**
> **username_0**: Thanks. I use you the code linked, the the result address http://codepad.org/nRJhvMC3 does not match the expected address https://www.blockchain.com/btc/block/1 So what's the usage of this `Decompiler`?  
> **username_1**: Oh, I see, interesting, I have some bug in the P2PK deserialization, sorry you have right.  I will fix it for the P2PK. if you run the script you have a complete summary where is contained the link to see the address information on an explorer. Sorry for the P2PK deserialization. I update the post with an example of how to use the code  
> **username_1**: I fixed the bug with this commit https://github.com/username_1/decompiler-bitcoin-script/commit/b5540532f2e15e867be44573af4617711db96f31  thanks so much and sorry, now you can see with the following command that you address if calculate the same `./Decompiler 410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac`. Look here the result https://blockstream.info/address/12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX  

---

