<p>It won't work, because there <em>is</em> no address for that script.</p>

<p>Addresses are templates to construct outputs from. Generally, you should not go the other way, as addresses may be misinterpreted as a place to send coins to, without the receiver asking for it or aware of it.</p>

<p>Furthermore, there are only a few common script types (P2PKH, P2SH, P2WPKH, P2WSH) that has associated addresses. Others, like your example, don't.</p>

CC BY-SA 3.0
2018-04-29T09:38:32.373Z
You say there is no address for this script, but why when i use this site to execute above script:

http://chainquery.com/bitcoin-api/decodescript

it is produced this valid address :
1MeeajrKNiF8WtD24S4DmVwEPQYJxeh7Ef
Saeed
CC BY-SA 3.0
2018-04-29T15:40:38.023Z
That's common practice, but incorrect. The script is a pay-to-pubkey (P2PK) script. The site is showing the address corresponding to the pay-to-pubkey-hash (P2PKH) script for the same key. You should never do this; the recipient may not expect payment to anything but the P2PK script.
Pieter Wuille
CC BY-SA 3.0
2018-04-29T08:36:06.257Z
2018-04-29T08:36:06.257Z
Pieter Wuille
<p>I'm working on bitcoin protocol and exactly i want to extract raw script from output script to gain address from tx messages.</p>

<p>for common scripts, like scripts start with 0x76(means <code>OP_DUP</code>),  we can access to address with these steps:</p>

<ol>
<li>add zeros to start of raw script.</li>
<li>hash with sha256.</li>
<li>hashed with sha256 again.</li>
<li>grab the first 4 bytes of this result and stick them on the end
of the raw script with leading zeros</li>
<li>then encode with base58.</li>
<li>at the end, add "1" to start of last output to gain output address.</li>
</ol>

<p>these steps are suitable for common scripts, but for scripts like this</p>

<pre><code>410498361908359fec5adaa624428484e7d117f36f811c7c471f4f1c7dd8184c20b32f0e2590c8d70906ebd585da2ae14ea942e4088891139379b434a26173754750ac
</code></pre>

<p>which is means:</p>

<pre><code>PUSH(0x41) 0498361908359fec5adaa624428484e7d117f36f811c7c471f4f1c7dd8184c20b32f0e2590c8d70906ebd585da2ae14ea942e4088891139379b434a26173754750 ac
</code></pre>

<p>it didn't work and the generated output isn't valid.</p>

CC BY-SA 3.0
2018-04-29T08:33:35.827Z
You need to hash160 the pubkey first
Raghav Sood
CC BY-SA 3.0
2018-04-29T08:38:42.123Z
To clarify against Pieter's answer, blockchain.info and other explorers will usually convert it to a p2pkh address. This script itself will not produce an address
Raghav Sood
<transactions><blockchain><hash><script><base58>
Extract output address from raw script in bitcoin protocol
Saeed
# Extract output address from raw script in bitcoin protocol

(Asked by: username_0 on 2018-04-29)

I'm working on bitcoin protocol and exactly i want to extract raw script from output script to gain address from tx messages.
for common scripts, like scripts start with 0x76(means OP_DUP),  we can access to address with these steps:

add zeros to start of raw script.
hash with sha256.
hashed with sha256 again.
grab the first 4 bytes of this result and stick them on the end
of the raw script with leading zeros
then encode with base58.
at the end, add "1" to start of last output to gain output address.

these steps are suitable for common scripts, but for scripts like this
410498361908359fec5adaa624428484e7d117f36f811c7c471f4f1c7dd8184c20b32f0e2590c8d70906ebd585da2ae14ea942e4088891139379b434a26173754750ac

which is means:
PUSH(0x41) 0498361908359fec5adaa624428484e7d117f36f811c7c471f4f1c7dd8184c20b32f0e2590c8d70906ebd585da2ae14ea942e4088891139379b434a26173754750 ac

it didn't work and the generated output isn't valid.

**Tags:** transactions, blockchain, hash, script, base58

> **Comments:**
> **username_1**: You need to hash160 the pubkey first  
> **username_1**: To clarify against Pieter's answer, blockchain.info and other explorers will usually convert it to a p2pkh address. This script itself will not produce an address  

---

## 1 answers

### Answer by username_2 on 2018-04-29. Score: 1

It won't work, because there *is* no address for that script.

Addresses are templates to construct outputs from. Generally, you should not go the other way, as addresses may be misinterpreted as a place to send coins to, without the receiver asking for it or aware of it.

Furthermore, there are only a few common script types (P2PKH, P2SH, P2WPKH, P2WSH) that has associated addresses. Others, like your example, don't.

> **Comments:**
> **username_0**: You say there is no address for this script, but why when i use this site to execute above script:  http://chainquery.com/bitcoin-api/decodescript  it is produced this valid address : 1MeeajrKNiF8WtD24S4DmVwEPQYJxeh7Ef  
> **username_2**: That's common practice, but incorrect. The script is a pay-to-pubkey (P2PK) script. The site is showing the address corresponding to the pay-to-pubkey-hash (P2PKH) script for the same key. You should never do this; the recipient may not expect payment to anything but the P2PK script.  

---

