Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
.. highlight:: haskell | ||
.. _exporting_a_script: | ||
|
||
How to export scripts, datums and redemmers | ||
How to export scripts, datums and redeemers | ||
=========================================== | ||
|
||
.. note:: | ||
This guide uses the scripts from the :ref:`basic validators tutorial <basic_validators_tutorial>`. | ||
|
||
While most :term:`Plutus Application` s use scripts by directly submitting them as part of transactions from the application itself, it can be useful to be able to export a serialized script. | ||
For example, you might want to submit it as part of a manually created transaction with the Cardano node CLI, send it to another party for them to use, or maybe just back it up. | ||
Since scripts must match their on-chain hashes exactly, it is important that the scripts which an application uses do not accidentally change. | ||
For example, changing the source code or updating dependencies or tooling may lead to small changes in the script - but since the hashes must match exactly, even small changes can be problematic. | ||
|
||
For this reason, once you expect that you will not modify the on-chain part of your application more, it is sensible to *freeze* it by saving the final Plutus Core to a file. | ||
|
||
Additionally, while most :term:`Plutus Application` s use scripts by directly submitting them as part of transactions from the application itself, it can be useful to be able to export a serialized script. | ||
For example, you might want to submit it as part of a manually created transaction with the Cardano node CLI, or send it to another party for them to use. | ||
|
||
Fortunately, it is quite simple to do this. | ||
You can either translate directly into CBOR using the `Serialise` typeclass from the `serialise` package, or you can create an envelope of the sort used by the Cardano node CLI. | ||
Most of the types have typeclass instances for ``Serialise`` which allows translating directly into CBOR. | ||
This applies to ``Validator``, ``Redeemer``, and ``Datum`` types. | ||
If you want to create values that you can pass to the Cardano CLI, you will need to convert them to the appropriate types from ``cardano-api`` and use ``serialiseToTextEnvelope``. | ||
|
||
The same can also be done with `Datum` and `Redeemer` datatypes. | ||
|
||
.. literalinclude:: ../tutorials/BasicValidators.hs | ||
:start-after: BLOCK8 | ||
:end-before: BLOCK9 | ||
|
||
``CompiledCode`` has a different serialization method, ``Flat``, but the principle is the same. | ||
|
||
The serialized form of ``CompiledCode`` can also be dumped using a plugin option: | ||
|
||
.. code-block:: haskell | ||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:dump-uplc #-} | ||
This will dump the output to a temporary file with a name based on the module name. | ||
The filename will be printed to the console when compiling the source file. | ||
You can then move it to a more permanent location. | ||
|
||
It can be read in conveniently with ``loadFromFile`` as an alternative to ``compile``. | ||
|
||
.. literalinclude:: ../tutorials/BasicValidators.hs | ||
:start-after: BLOCK9 | ||
:end-before: BLOCK10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters