<p>As stated by Samuel, the code that a validator runs to check whether a transaction is valid is sent and stored in the transaction body as an input.</p>
<p>So all scripts, be they Plutus or Native scripts, get stored on chain when any UTxO's locked by the script are consumed (though they are not part of the UTxO ledger state, but stored in another part of the ledger) and are retrievable through the chain-indexer, Blockfrost or even in some cases, from some blockchain explorers.</p>
<p>For example, you can use the Blockfrost API &quot;<a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D%7E1cbor/get" rel="nofollow noreferrer">Script CBOR</a>&quot; to access the script CBOR. <a href="https://github.com/mallapurbharat/cardano-tx-sample/blob/513ef239cf182172d9a1afc1ae3ebb94b85b9bdb/plutus/getPlutusCBOR.md" rel="nofollow noreferrer">Here's a link</a> to understand how to do this.</p>
<p>Additionally, if you just look at a sample transaction on CardanoScan itself, for example this transaction claiming an UTxO for the simple &quot;<em>Always succeed</em>&quot; plutus script address [<a href="https://cardanoscan.io/transaction/f5f72ad369da02c772f8e158aaf3ccd41681e73693887f7a38158c53341d495d?tab=contracts" rel="nofollow noreferrer">3</a>], we can see that the datum in CBOR is 182a.</p>
<p>Using an online tool caller <a href="http://cbor.me/" rel="nofollow noreferrer">cbor.me</a> we see that the datum/redeemer was 42 (182a in CBOR hex). The contract bytecode is also listed there, but this is not human-readable plutus core code.</p>
<p>Now for the off-chain part that safely can construct transactions for users, that needs to be distributed by the writer of that script. I know that IOG (also known as IOHK) is building a Dapp store to safely distribute such offline code.</p>
<p>And lastly, you are correct! The plutus script hashes to the address, so if one would change the code, a new address should be used. Note however that complex Dapps may use several contracts, for example look at the Occam dex that they showed off [<a href="https://testnet.cardanoscan.io/transaction/c4650b25dadf55a3d932e320b21432ceb59a8f1d5450400f02fd2f9c97077053?tab=contracts" rel="nofollow noreferrer">5</a>] They used 3 contracts to implement certain behavior. So over time use cases may change, and other addresses might be used.</p>
<p><strong>EDIT</strong>
After the Vasil HF in the Babbage era, transactions can witness the scripts by referencing them in other UTxO's that may not be consumed in the transaction. This way, scripts do get stored on the active UTxO graph part of the ledger. These referenced validators will also become available inside plutus <a href="https://github.com/input-output-hk/plutus/blob/00b2fc41080e544e3e93ac6f1274745100e81dd3/plutus-ledger-api/src/PlutusLedgerApi/V2/Tx.hs#L84" rel="nofollow noreferrer">(6)</a>.</p>

CC BY-SA 4.0
2021-10-31T18:38:06.443Z
2022-08-08T12:20:05.343Z
2022-08-08T12:20:05.343Z
Fermat
<p>Auxiliary scripts are an attribute in the txbody that can have the validator script in it if it's small enough. You could also have metadata that links your users to the script off-chain.</p>

CC BY-SA 4.0
2021-10-01T15:53:20.320Z
2021-10-01T15:53:20.320Z
Samuel Leathers
<p>I've just read something that suggests <a href="https://medium.com/@gianmarcoturchiano/whats-so-different-about-cardano-smart-contracts-anyway-5cbf3c95aa4b" rel="noreferrer">Validators aren't actually kept on the blockchain</a>. To save the space, only the hash of the Validator is kept at the UTxO and users willing to spend it must themselves provide the Validator code with matching hash value.</p>
<p>Besides the funny fact that on-chain code doesn't actually live on the chain, that brings a number of questions, of which the first and most obvious will be:</p>
<ol>
<li>How the actual Validators are stored? I mean the repositories may and should be distributed and each SC author could provide their own source of the code, but</li>
<li>Is there any standard format of such packages (most likely containing also off-chain code) that could be loaded into wallets or other clients?</li>
<li>Since the hash refers to a compiled version of the Validator, i.e. the <em>Plutus Script</em> code, how could users make sure that the binary is a result of compilation of the source the author publishes? Having the compilator and libraries being developed and optimized, it's almost sure the compilation results will vary over time, obviously changing the hash.</li>
</ol>

<plutus><smart-contract><validator><on-chain>
Where is the on-chain code actually stored?
# Where is the on-chain code actually stored?

(Asked by: username_0 on 2021-09-18)

I've just read something that suggests [Validators aren't actually kept on the blockchain](https://medium.com/@gianmarcoturchiano/whats-so-different-about-cardano-smart-contracts-anyway-5cbf3c95aa4b). To save the space, only the hash of the Validator is kept at the UTxO and users willing to spend it must themselves provide the Validator code with matching hash value.

Besides the funny fact that on-chain code doesn't actually live on the chain, that brings a number of questions, of which the first and most obvious will be:

1. How the actual Validators are stored? I mean the repositories may and should be distributed and each SC author could provide their own source of the code, but
2. Is there any standard format of such packages (most likely containing also off-chain code) that could be loaded into wallets or other clients?
3. Since the hash refers to a compiled version of the Validator, i.e. the *Plutus Script* code, how could users make sure that the binary is a result of compilation of the source the author publishes? Having the compilator and libraries being developed and optimized, it's almost sure the compilation results will vary over time, obviously changing the hash.

**Tags:** plutus, smart-contract, validator, on-chain

---

## 2 answers

### Answer by username_1 on 2021-10-31. Score: 7 | Accepted answer

As stated by Samuel, the code that a validator runs to check whether a transaction is valid is sent and stored in the transaction body as an input.

So all scripts, be they Plutus or Native scripts, get stored on chain when any UTxO's locked by the script are consumed (though they are not part of the UTxO ledger state, but stored in another part of the ledger) and are retrievable through the chain-indexer, Blockfrost or even in some cases, from some blockchain explorers.

For example, you can use the Blockfrost API "[Script CBOR](https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D%7E1cbor/get)" to access the script CBOR. [Here's a link](https://github.com/mallapurbharat/cardano-tx-sample/blob/513ef239cf182172d9a1afc1ae3ebb94b85b9bdb/plutus/getPlutusCBOR.md) to understand how to do this.

Additionally, if you just look at a sample transaction on CardanoScan itself, for example this transaction claiming an UTxO for the simple "*Always succeed*" plutus script address [[3](https://cardanoscan.io/transaction/f5f72ad369da02c772f8e158aaf3ccd41681e73693887f7a38158c53341d495d?tab=contracts)], we can see that the datum in CBOR is 182a.

Using an online tool caller [cbor.me](http://cbor.me/) we see that the datum/redeemer was 42 (182a in CBOR hex). The contract bytecode is also listed there, but this is not human-readable plutus core code.

Now for the off-chain part that safely can construct transactions for users, that needs to be distributed by the writer of that script. I know that IOG (also known as IOHK) is building a Dapp store to safely distribute such offline code.

And lastly, you are correct! The plutus script hashes to the address, so if one would change the code, a new address should be used. Note however that complex Dapps may use several contracts, for example look at the Occam dex that they showed off [[5](https://testnet.cardanoscan.io/transaction/c4650b25dadf55a3d932e320b21432ceb59a8f1d5450400f02fd2f9c97077053?tab=contracts)] They used 3 contracts to implement certain behavior. So over time use cases may change, and other addresses might be used.

**EDIT**
After the Vasil HF in the Babbage era, transactions can witness the scripts by referencing them in other UTxO's that may not be consumed in the transaction. This way, scripts do get stored on the active UTxO graph part of the ledger. These referenced validators will also become available inside plutus [(6)](https://github.com/input-output-hk/plutus/blob/00b2fc41080e544e3e93ac6f1274745100e81dd3/plutus-ledger-api/src/PlutusLedgerApi/V2/Tx.hs#L84).


---

### Answer by username_2 on 2021-10-01. Score: 1

Auxiliary scripts are an attribute in the txbody that can have the validator script in it if it's small enough. You could also have metadata that links your users to the script off-chain.


---

