You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/how-to/commit-script-utxo.md
+31-5Lines changed: 31 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,12 @@ sidebar_position: 2
6
6
7
7
This guide provides a walkthrough on how to commit a UTxO from a script into a Hydra Head.
8
8
9
+
A **Script UTxO** is a special kind of Unspent Transaction Output (UTxO) that isn't controlled by a simple private key. Instead, it's locked by a script—a small program that runs on the blockchain. To spend the funds in a Script UTxO, you must provide data (a "redeemer" and "datum") that satisfies the conditions defined in that script.
10
+
11
+
Committing a script UTxO to a Hydra Head is a powerful feature that allows for more complex on-chain validation logic to be brought into the Head. This is useful for scenarios where you need to enforce specific rules on how funds can be spent, even within the Head's off-chain environment.
12
+
13
+
This tutorial will guide you through the entire process, which involves creating a script, locking an on-chain UTxO with it, and then preparing a special "blueprint" transaction to commit this script UTxO into an open Head.
14
+
9
15
## Prerequisites
10
16
11
17
This tutorial assumes you are familiar with the process of committing a standard UTxO to a Hydra Head. If you are not, please first read the [Commit using a blueprint](./commit-blueprint.md) tutorial.
@@ -60,19 +66,35 @@ cardano-cli query utxo \
60
66
--socket-path testnets/preprod/node.socket
61
67
```
62
68
63
-
Pick a UTxO from the output and use it to build a transaction that sends funds to the script address. Let's say you picked a UTxO with TxHash `a5a11c..` and index `0` containing `100 ADA`. We'll send `10 ADA` to the script address:
69
+
Pick a UTxO from the output and use it to build a transaction that sends funds to the script address. Let's say you picked a UTxO with TxHash `<UTXO_TXIX>` containing `100 ADA`. We'll send `10 ADA` to the script address.
70
+
71
+
First, create a file named `datum.json` that contains the datum. For this example, we will just use the integer `42`.
Note that we are also providing a datum value `42`. Even though our script does not use it, a datum is required for all script UTxOs.
96
+
97
+
Note that we are also providing an inline datum via the `datum.json` file. Even though our script does not use it, a datum is required for all script UTxOs.
76
98
77
99
Now, sign and submit the transaction:
78
100
@@ -101,19 +123,23 @@ cardano-cli query utxo \
101
123
102
124
Now we are ready to prepare the commit. We'll create a blueprint transaction that spends the script UTxO. Note that this transaction is not meant to be signed and submitted to the Cardano network. It's just a blueprint that we'll send to the `hydra-node` to get a properly drafted commit transaction.
103
125
126
+
We use `cardano-cli ... build-raw` to construct this blueprint because it gives us full control over the transaction structure without trying to automatically balance it or calculate fees, which is perfect for a blueprint.
127
+
104
128
In this transaction, we'll spend the script UTxO and send the funds to our own wallet address.
As you can see, we are providing the script file, the datum, and a redeemer. Our "always-true" script doesn't actually check any of these, but they are required for a valid transaction spending a script UTxO.
141
+
142
+
A real-world script, like one written in [Aiken](https://aiken-lang.org/), would use the datum to carry state and the redeemer to provide input for validation. Our "always-true" script doesn't actually check any of these, but they are still required fields for a valid transaction that spends a script UTxO. Note that we also provide `--tx-in-execution-units`. This is required for any script spend to tell the network how much computational resource to budget for the script's execution. Since our script does nothing, we can use `(0, 0)`.
0 commit comments