<p>First of all on-chain code isn't stored in the blockchain, the hash of on-chain code is.</p>
<p>To use on-chain validator on testnet or mainnet steps are:</p>
<ol>
<li>Compile on-chain code into plutus script</li>
<li>Generate address from plutus script</li>
<li>Lock funds into plutus script address (<a href="https://github.com/input-output-hk/cardano-node/issues/3069" rel="nofollow noreferrer">Don't forget Datum!!!</a>)</li>
<li>Pass plutus script for validation to unlock funds from plutus script address</li>
</ol>
<p>You can try going trough <a href="https://github.com/input-output-hk/Alonzo-testnet/blob/main/Alonzo-solutions/exercise3/e3SampleSolution.md" rel="nofollow noreferrer">Alonzo exercises</a> for an example how to do all of these steps.</p>
<p>And as for certification I don't think there is an official available certification <a href="https://iohk.io/en/blog/posts/2021/10/25/new-certification-levels-for-smart-contracts-on-cardano/" rel="nofollow noreferrer">yet</a></p>

CC BY-SA 4.0
2022-01-25T15:48:27.303Z
I think that statement - that on-chain code is not stored on the blockchain - can be a little misleading. It might not be stored (or even executed) directly in that first locking transaction, but when you compose a transaction to spend those funds that transaction will hold the script, which will be stored and made visible on the blockchain and it is also executed directly on-chain by every node validating the transaction. Please correct me if Im wrong here.
sean
CC BY-SA 4.0
2022-01-25T15:49:00.833Z
(Looking at cardano-db-sync it even creates a table for the scripts that it takes directly from the blockchain: https://github.com/input-output-hk/cardano-db-sync/blob/2a0600a16425bce26b4973debc28cddfb45c6eb3/doc/schema.md#script)
sean
CC BY-SA 4.0
2022-01-25T16:05:32.413Z
To add to the answer, here's two resources on how to publish the on-chain code: https://plutus.readthedocs.io/en/latest/plutus/howtos/exporting-a-script.html
https://docs.cardano.org/plutus/Plutus-transactions (scroll down to 3. Create your transaction with the accompanying Plutus script(s))
sean
CC BY-SA 4.0
2022-01-25T17:34:15.627Z
Yeah, that seems to be true. The `--tx-in-script-file` param of `cardano-cli transaction build` is saving the file in the transaction, so a given node can run the script code from that transaction.
Walker Leite
CC BY-SA 4.0
2022-01-25T13:15:50.137Z
2022-01-25T13:15:50.137Z
KugisMugis
<p>I've understand that the on-chain code is stored in the blockchain through Playground module which is in sync against a local node. But how to &quot;publish&quot; this code to run anywhere? It's an accessible process, It must have some &quot;certification&quot;?</p>

<plutus-pioneer-program><plutus-playground><testnet><mainnet><lovelace-academy>
How do you publish on-chain code to mainnet and testnet?
# How do you publish on-chain code to mainnet and testnet?

(Asked by: username_0 on 2022-01-17)

I've understand that the on-chain code is stored in the blockchain through Playground module which is in sync against a local node. But how to "publish" this code to run anywhere? It's an accessible process, It must have some "certification"?

**Tags:** plutus-pioneer-program, plutus-playground, testnet, mainnet, lovelace-academy

---

## 1 answers

### Answer by username_1 on 2022-01-25. Score: 4 | Accepted answer

First of all on-chain code isn't stored in the blockchain, the hash of on-chain code is.

To use on-chain validator on testnet or mainnet steps are:

1. Compile on-chain code into plutus script
2. Generate address from plutus script
3. Lock funds into plutus script address ([Don't forget Datum!!!](https://github.com/input-output-hk/cardano-node/issues/3069))
4. Pass plutus script for validation to unlock funds from plutus script address

You can try going trough [Alonzo exercises](https://github.com/input-output-hk/Alonzo-testnet/blob/main/Alonzo-solutions/exercise3/e3SampleSolution.md) for an example how to do all of these steps.

And as for certification I don't think there is an official available certification [yet](https://iohk.io/en/blog/posts/2021/10/25/new-certification-levels-for-smart-contracts-on-cardano/)

> **Comments:**
> **username_2**: I think that statement - that on-chain code is not stored on the blockchain - can be a little misleading. It might not be stored (or even executed) directly in that first locking transaction, but when you compose a transaction to spend those funds that transaction will hold the script, which will be stored and made visible on the blockchain and it is also executed directly on-chain by every node validating the transaction. Please correct me if Im wrong here.  
> **username_2**: (Looking at cardano-db-sync it even creates a table for the scripts that it takes directly from the blockchain: https://github.com/input-output-hk/cardano-db-sync/blob/2a0600a16425bce26b4973debc28cddfb45c6eb3/doc/schema.md#script)  
> **username_2**: To add to the answer, here's two resources on how to publish the on-chain code: https://plutus.readthedocs.io/en/latest/plutus/howtos/exporting-a-script.html https://docs.cardano.org/plutus/Plutus-transactions (scroll down to 3. Create your transaction with the accompanying Plutus script(s))  
> **username_0**: Yeah, that seems to be true. The `--tx-in-script-file` param of `cardano-cli transaction build` is saving the file in the transaction, so a given node can run the script code from that transaction.  

---

