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
Before we can commit a script UTxO, we need to create one. This is done by sending funds to the script address.
68
69
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`:
70
+
First, we need a UTxO in a wallet to fund the transaction. The following command will find the first available UTxO in a wallet funded by`alice-funds.sk`, and export its transaction input (`TxIn`) to an environment variable.
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.
77
+
Now that we have a funding UTxO, we can build the transaction to lock 10 ADA at the script address.
78
78
79
79
First, create a file named `datum.json` that contains the datum. For this example, we will just use the integer `42`.
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.
130
129
131
130
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.
132
131
133
-
In this transaction, we will spend the script UTxO and send the funds to our own wallet address.
132
+
For a script UTxO, the blueprint only needs to declare the script UTxO as an input. The `hydra-node` will use this, along with the UTxO context provided in the next step, to build the full 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)`.
148
147
149
-
## Step 6: Commit the script UTxO
148
+
## Step 6: Prepare the commit
150
149
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`.
150
+
This final step brings everything together. We will start a `hydra-node`, initialize a Head, and then send our blueprint and UTxO context to the `/commit` endpoint.
152
151
153
-
First, start the `hydra-node` and `hydra-tui` as explained in the [Commit using a blueprint](./commit-blueprint.md#step-5) tutorial and initialize a Head.
152
+
**1. Start the Hydra Node and TUI**
154
153
155
-
Once the Head is in the `Initializing` state, you can send the HTTP request to the `/commit` API path.
154
+
In a **new terminal**, start a single-party `hydra-node`.
Just like in the other tutorial, you need to assemble a JSON request body. The `blueprintTx` is the `tx.json` file we just created, and the `utxo` is the script UTxO you are committing.
166
+
In another **new terminal**, start the `hydra-tui`.
In the TUI, press `i` to initialize the Head. Once the state is `Initializing`, you can quit the TUI (`q`) and proceed.
158
173
159
-
You can use the following script to query the necessary information and generate the `commit-request.json` file automatically. Make sure to replace `<SCRIPT_UTXO_TXIX>` with the actual transaction input of your script UTxO.
174
+
**2. Send the Commit Request**
175
+
176
+
Now, we will build the commit request. This request contains two parts: the `utxo` context (which must include the script) and the `blueprintTx` (which provides the witness information).
@@ -178,14 +194,15 @@ Now, use `curl` to send the request to the `hydra-node`, which will respond with
178
194
curl -X POST --data @commit-request.json http://127.0.0.1:4001/commit > commit-tx.json
179
195
```
180
196
181
-
This will give you the commit transaction, which you can then sign and submit as usual.
182
-
The commit transaction must be signed by two keys: the key for the funds you are committing, and the party key that is participating in the Head.
197
+
**3. Sign and Submit**
198
+
199
+
This is the final step. The `commit-tx.json` file now contains a valid, balanced transaction drafted by the `hydra-node`. We just need to sign it with both our funds key and our party key, and then submit it.
0 commit comments