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
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,16 @@ You will also need:
22
22
-`cardano-cli` in your `PATH`.
23
23
-`hydra-node` and `hydra-tui` in your `PATH`.
24
24
25
-
## Step 1: Create the script
25
+
## Step 1: Set Up Your Environment
26
+
27
+
To avoid specifying the network identifier and the path to the node's socket in every command, you can set the following environment variables in your shell. Make sure to replace the values with the ones that are appropriate for your setup (e.g., for the pre-production testnet, the magic is `1`).
For this tutorial, we will use a simple "always true" validator script. This script will always succeed, regardless of the redeemer or datum.
28
37
@@ -36,14 +45,14 @@ Create a file named `always-true.plutus` with the following content:
36
45
}
37
46
```
38
47
39
-
## Step 2: Create the script address
48
+
## Step 3: Create the script address
40
49
41
50
Now, we need to create an address for this script. We can do this using `cardano-cli`:
42
51
43
52
```shell
44
53
cardano-cli address build \
45
54
--payment-script-file always-true.plutus \
46
-
--testnet-magic 1 \
55
+
--testnet-magic $CARDANO_TESTNET_MAGIC \
47
56
--out-file script.addr
48
57
```
49
58
@@ -53,17 +62,16 @@ This will create a file named `script.addr` containing the script address. You c
53
62
cat script.addr
54
63
```
55
64
56
-
## Step 3: Lock funds in the script address
65
+
## Step 4: Lock funds in the script address
57
66
58
67
Before we can commit a script UTxO, we need to create one. This is done by sending funds to the script address.
59
68
60
69
First, find a UTxO in your wallet that you can use. You can query your wallet's UTxOs using `cardano-cli`. For this example, we will use `alice-funds.sk`:
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 will send `10 ADA` to the script address.
Once the transaction is confirmed, you can query the script address to see the newly created UTxO:
114
120
115
121
```shell
116
122
cardano-cli query utxo \
117
123
--address $(cat script.addr) \
118
-
--testnet-magic 1 \
119
-
--socket-path testnets/preprod/node.socket
124
+
--testnet-magic $CARDANO_TESTNET_MAGIC
120
125
```
121
126
122
-
## Step 4: Prepare the commit
127
+
## Step 5: Prepare the commit
123
128
124
129
Now we are ready to prepare the commit. We will 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 is just a blueprint that we will send to the `hydra-node` to get a properly drafted commit transaction.
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 use `--tx-in-inline-datum-present` because the datum was already included on-chain when we created the script UTxO. 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)`.
143
148
144
-
## Step 5: Commit the script UTxO
149
+
## Step 6: Commit the script UTxO
145
150
146
151
This final step is very similar to the standard commit tutorial. We will start a `hydra-node`, initialize a Head, and then use the blueprint transaction to get a commit transaction from the `hydra-node`.
147
152
@@ -157,7 +162,7 @@ You can use the following script to query the necessary information and generate
0 commit comments