<p>Thought I'd give some context for others who might come across this.</p>
<h4>The short answer:</h4>
<p>No, you cannot derive it directly because the script address only exposes the script <code>hash</code>.<br />
You <b>can</b> however find it using tools like <a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D%7E1cbor/get" rel="nofollow noreferrer">this</a> Blockfrost endpoint</p>
<h4>Long answer:</h4>
<p>Cardano addresses are made up of 3 parts; a header, payment part, and a delegation part.</p>
<pre><code>   addr1  zxgx3far7qygq0k6epa0zcvcvrevmn0ypsnfsue94nsn3tvpw  288a4x0xf8pxgcntelxmyclq83s0ykeehchz2wtspks905plm
| header |                  payment part                    |                 delegation part                 |
</code></pre>
<p>If you decode to Hex you get</p>
<pre><code>    11     9068a7a3f008803edac87af1619860f2cdcde40c26987325ace138ad  81728e7ed4cf324e1323135e7e6d931f01e30792d9cdf17129cb806d
| header |                      payment part                       |                     delegation part                     |
</code></pre>
<p>The payment part in the above tells a node how to validate the transaction:</p>
<ul>
<li>Either it is a <code>pubkeyhash</code> from a wallet, in which case the node checks for that wallets signature</li>
<li>Or it is the <code>hash of a script</code>, in which case the node checks for an attached script and executes it</li>
</ul>
<p><b>This means that the only information you know from a script address is the hash of the script, and there is no way to directly derive the script bytes from this due to the nature of hashing</b></p>
<p>If you use a tool like the Blockfrost <a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D%7E1cbor/get" rel="nofollow noreferrer">endpoint</a> above to get the script, you must provide the <code>script hash</code> which you can get from the payment part of the HEX representation of the address.</p>

CC BY-SA 4.0
2023-04-05T10:44:19.107Z
2023-04-05T14:15:15.813Z
2023-04-05T14:15:15.813Z
zing
<p>From some indexer, yes as it is common to support fetching script's information from it's hash. <a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D/get" rel="nofollow noreferrer">Here</a> is an API endpoint for Blockfrost.</p>
<p>To obtain script's hash from its <code>bech32</code> encoded address, you would first need to decode this <code>bech32</code> encoding and then remove the 1 byte header (see <a href="https://cips.cardano.org/cips/cip19/" rel="nofollow noreferrer">CIP-19</a>).</p>

CC BY-SA 4.0
2023-04-02T14:25:34.607Z
2023-04-02T14:25:34.607Z
Sourabh
<p>While all answers are insightful, here is an example that makes it possible to entirely get the jpg.store script bytecode from just its script hash obtained from the bech32 address, using the pycardano and python-blockfrost libraries:</p>
<pre class="lang-python prettyprint-override"><code>from pycardano import (
    BlockFrostChainContext, 
    Address,
    PlutusV2Script
)
import cbor2
from blockfrost import ApiUrls


# ------- Chain context
chain_context = BlockFrostChainContext(
    project_id=&quot;mainnetslL7jFzg8p4Hxk8pcJCRIcWvcM6P6FZE&quot;,
    base_url=ApiUrls.mainnet.value
)
jpg_store_addr = Address.from_primitive(&quot;addr1zxgx3far7qygq0k6epa0zcvcvrevmn0ypsnfsue94nsn3tvpw288a4x0xf8pxgcntelxmyclq83s0ykeehchz2wtspks905plm&quot;)
script_hash = jpg_store_addr.payment_part
script_cbor = chain_context.api.script_cbor(str(script_hash)).cbor
script_bytes = PlutusV2Script(cbor2.loads(bytes.fromhex(script_cbor)))
print(script_bytes.hex())  # equals jpg.store script bytecode as shown on cardanoscan
</code></pre>

CC BY-SA 4.0
2023-04-24T09:40:23.450Z
2023-04-24T09:40:23.450Z
zaherr
<p>To expand on the previous answer, you can use <a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D/get" rel="nofollow noreferrer">https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D/get</a> endpoint and a TypeScript conversion function from here <a href="https://github.com/blockfrost/blockfrost-utils/blob/40964699913a54417371c63739e6d0c19712dca1/src/validation.ts#L220-L235" rel="nofollow noreferrer">https://github.com/blockfrost/blockfrost-utils/blob/40964699913a54417371c63739e6d0c19712dca1/src/validation.ts#L220-L235</a></p>

CC BY-SA 4.0
2023-04-03T08:40:11.697Z
2023-04-03T08:40:11.697Z
sorki
<p>I would like to get the script bytes from the bech32 address of a script. Is this possible?</p>

<plutus><cardano-address><script><script-addresses>
Is it possible to obtain the cbor hex/script bytes from a bech32 script address?
# Is it possible to obtain the cbor hex/script bytes from a bech32 script address?

(Asked by: username_0 on 2023-04-01)

I would like to get the script bytes from the bech32 address of a script. Is this possible?

**Tags:** plutus, cardano-address, script, script-addresses

---

## 4 answers

### Answer by username_1 on 2023-04-05. Score: 1

Thought I'd give some context for others who might come across this.
The short answer:
No, you cannot derive it directly because the script address only exposes the script hash.
You can however find it using tools like this Blockfrost endpoint
Long answer:
Cardano addresses are made up of 3 parts; a header, payment part, and a delegation part.
   addr1  zxgx3far7qygq0k6epa0zcvcvrevmn0ypsnfsue94nsn3tvpw  288a4x0xf8pxgcntelxmyclq83s0ykeehchz2wtspks905plm
| header |                  payment part                    |                 delegation part                 |

If you decode to Hex you get
    11     9068a7a3f008803edac87af1619860f2cdcde40c26987325ace138ad  81728e7ed4cf324e1323135e7e6d931f01e30792d9cdf17129cb806d
| header |                      payment part                       |                     delegation part                     |

The payment part in the above tells a node how to validate the transaction:

Either it is a pubkeyhash from a wallet, in which case the node checks for that wallets signature
Or it is the hash of a script, in which case the node checks for an attached script and executes it

This means that the only information you know from a script address is the hash of the script, and there is no way to directly derive the script bytes from this due to the nature of hashing
If you use a tool like the Blockfrost endpoint above to get the script, you must provide the script hash which you can get from the payment part of the HEX representation of the address.


---

### Answer by username_2 on 2023-04-02. Score: 1

From some indexer, yes as it is common to support fetching script's information from it's hash. [Here](https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D/get) is an API endpoint for Blockfrost.

To obtain script's hash from its `bech32` encoded address, you would first need to decode this `bech32` encoding and then remove the 1 byte header (see [CIP-19](https://cips.cardano.org/cips/cip19/)).


---

### Answer by username_0 on 2023-04-24. Score: 1

While all answers are insightful, here is an example that makes it possible to entirely get the jpg.store script bytecode from just its script hash obtained from the bech32 address, using the pycardano and python-blockfrost libraries:
from pycardano import (
    BlockFrostChainContext, 
    Address,
    PlutusV2Script
)
import cbor2
from blockfrost import ApiUrls


# ------- Chain context
chain_context = BlockFrostChainContext(
    project_id="mainnetslL7jFzg8p4Hxk8pcJCRIcWvcM6P6FZE",
    base_url=ApiUrls.mainnet.value
)
jpg_store_addr = Address.from_primitive("addr1zxgx3far7qygq0k6epa0zcvcvrevmn0ypsnfsue94nsn3tvpw288a4x0xf8pxgcntelxmyclq83s0ykeehchz2wtspks905plm")
script_hash = jpg_store_addr.payment_part
script_cbor = chain_context.api.script_cbor(str(script_hash)).cbor
script_bytes = PlutusV2Script(cbor2.loads(bytes.fromhex(script_cbor)))
print(script_bytes.hex())  # equals jpg.store script bytecode as shown on cardanoscan


---

### Answer by username_3 on 2023-04-03. Score: 1

To expand on the previous answer, you can use <https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D/get> endpoint and a TypeScript conversion function from here <https://github.com/blockfrost/blockfrost-utils/blob/40964699913a54417371c63739e6d0c19712dca1/src/validation.ts#L220-L235>


---

