|
| 1 | +--- |
| 2 | +sidebar_position: 99 |
| 3 | +--- |
| 4 | + |
| 5 | +# Commit using blueprint transaction |
| 6 | + |
| 7 | + This is a small walk-through on how to use `cardano-cli` to assemble everything needed to commit funds to a `Head` using blueprint transaction. |
| 8 | + |
| 9 | + Example assumes you have the hydra-node repo at your disposal together with `hydra-node`, `hydra-tui`, `cardano-cli` and `curl` binaries. |
| 10 | + |
| 11 | + We can use `cardano-cli` to create a _blueprint_ transaction from some `UTxO` we own. |
| 12 | + |
| 13 | + First we need a running cardano-node so let's spin one on the preprod network: |
| 14 | + |
| 15 | + |
| 16 | + ```shell |
| 17 | + ./testnets/cardano-node.sh ~/code/hydra/testnets/preprod |
| 18 | + ``` |
| 19 | + |
| 20 | + Now we need to find the `UTxO` you want to commit to the `Head` |
| 21 | + |
| 22 | + In this example we will use Alice and her external wallet key so first let's find out the address: |
| 23 | + |
| 24 | + ```shell |
| 25 | + cardano-cli address build \ |
| 26 | + --payment-verification-key-file hydra-cluster/config/credentials/alice-funds.vk \ |
| 27 | + --testnet-magic 1 |
| 28 | + |
| 29 | +addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z |
| 30 | + ``` |
| 31 | + |
| 32 | +and query to see what `UTxO` Alice has: |
| 33 | + |
| 34 | +```shell |
| 35 | +cardano-cli query utxo \ |
| 36 | + --socket-path testnets/preprod/node.socket \ |
| 37 | + --address addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z \ |
| 38 | + --testnet-magic 1 \ |
| 39 | + --output-json |
| 40 | + |
| 41 | +{ |
| 42 | + "14ab373afb1112d925b0f6a84518ac26d4a8cfcc99231e1f47e6996182e843a9#0": { |
| 43 | + "address": "addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z", |
| 44 | + "datum": null, |
| 45 | + "datumhash": null, |
| 46 | + "inlineDatum": null, |
| 47 | + "referenceScript": null, |
| 48 | + "value": { |
| 49 | + "lovelace": 8000000 |
| 50 | + } |
| 51 | + }, |
| 52 | + "14ab373afb1112d925b0f6a84518ac26d4a8cfcc99231e1f47e6996182e843a9#1": { |
| 53 | + "address": "addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z", |
| 54 | + "datum": null, |
| 55 | + "datumhash": null, |
| 56 | + "inlineDatum": null, |
| 57 | + "referenceScript": null, |
| 58 | + "value": { |
| 59 | + "lovelace": 1828427 |
| 60 | + } |
| 61 | + }, |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +Let's pick the first `UTxO` which has total of 8 ADA available. Let's use 5 ADA to commit and rely on `hydra-node` to balance the commit transaction. |
| 66 | + |
| 67 | +```shell |
| 68 | +cardano-cli transaction build-raw \ |
| 69 | + --babbage-era \ |
| 70 | + --tx-in 14ab373afb1112d925b0f6a84518ac26d4a8cfcc99231e1f47e6996182e843a9#0 \ |
| 71 | + --tx-out addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z+5000000 \ |
| 72 | + --fee 0 \ |
| 73 | + --out-file tx.json |
| 74 | +``` |
| 75 | + |
| 76 | +So now we have the _blueprint_ transaction present in the `tx.json` file. |
| 77 | + |
| 78 | +In order to have `hydra-node` give us a draft commit transaction we need to: |
| 79 | + |
| 80 | +- Obtain protocol-parameters needed to run the `hydra-node` |
| 81 | +- Have the `hydra-node` up and running |
| 82 | +- Have the `Head` in the initializing state |
| 83 | +- Submit the http request to the `hydra-node` api server using the _blueprint_ transaction we just created and the `UTxO` used for it's input. |
| 84 | + |
| 85 | + |
| 86 | +Query the preview protocol-parameters: |
| 87 | + |
| 88 | +```shell |
| 89 | +cardano-cli query protocol-parameters \ |
| 90 | + --testnet-magic 1 \ |
| 91 | + --socket-path testnets/preprod/node.socket \ |
| 92 | + --out-file pp-preprod.json |
| 93 | + |
| 94 | +``` |
| 95 | + |
| 96 | +Start the `hydra-node` in as a _single_ party Head instance. |
| 97 | + |
| 98 | +Note: The value `6264cee4d5eab3fb58ab67f3899ecbcc0d7e72732a2d9c1c5d638115db6ca711` comes from `hydra-node` release [0.16.0](https://github.com/input-output-hk/hydra/releases/tag/0.16.0) |
| 99 | + |
| 100 | +```shell |
| 101 | +hydra-node \ |
| 102 | + --node-id 1 --port 5001 --api-port 4001 \ |
| 103 | + --hydra-signing-key demo/alice.sk \ |
| 104 | + --hydra-scripts-tx-id 6264cee4d5eab3fb58ab67f3899ecbcc0d7e72732a2d9c1c5d638115db6ca711 \ |
| 105 | + --cardano-signing-key hydra-cluster/config/credentials/alice.sk \ |
| 106 | + --ledger-protocol-parameters pp-preprod.json \ |
| 107 | + --testnet-magic 1 \ |
| 108 | + --node-socket testnets/preprod/node.socket \ |
| 109 | + --persistence-dir . |
| 110 | +``` |
| 111 | + |
| 112 | +Now we can start `hydra-tui` and initialize the `Head`: |
| 113 | + |
| 114 | +```shell |
| 115 | +hydra-tui \ |
| 116 | + --connect 0.0.0.0:4001 \ |
| 117 | + --cardano-signing-key hydra-cluster/config/credentials/alice-funds.sk \ |
| 118 | + --testnet-magic 1 \ |
| 119 | + --node-socket testnets/preprod/node.socket |
| 120 | +``` |
| 121 | + |
| 122 | +Now press `i` to initialize the `Head`. |
| 123 | + |
| 124 | +Once we see that the head is in the `Initializing` state we are ready to send the HTTP request to the `/commit` API path. |
| 125 | + |
| 126 | +To assemble the request body we will use the `cborHex` field from the tx-body file `tx.json`. |
| 127 | + |
| 128 | +To get the json representation of the `UTxO` we used as the input we can just copy/paste the output we got from cardano-cli when we did a `UTxO` query: |
| 129 | + |
| 130 | +This is the valid json request: |
| 131 | + |
| 132 | +```shell |
| 133 | +{ |
| 134 | + "blueprintTx": { |
| 135 | + "cborHex": "84a3008182582014ab373afb1112d925b0f6a84518ac26d4a8cfcc99231e1f47e6996182e843a900018182581d6069830961c6af9095b0f2648dff31fa9545d8f0b6623db865eb78fde81a007a12000200a0f5f6", |
| 136 | + "description": "", |
| 137 | + "type": "Tx BabbageEra" |
| 138 | + }, |
| 139 | + "utxo": { |
| 140 | + "14ab373afb1112d925b0f6a84518ac26d4a8cfcc99231e1f47e6996182e843a9#0": { |
| 141 | + "address": "addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z", |
| 142 | + "datum": null, |
| 143 | + "datumhash": null, |
| 144 | + "inlineDatum": null, |
| 145 | + "referenceScript": null, |
| 146 | + "value": { |
| 147 | + "lovelace": 8000000 |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | +``` |
| 153 | + |
| 154 | +Let's save this json to commit-request.json file. |
| 155 | + |
| 156 | +Now, it is time to ask the running `hydra-node` to draft a commit transaction for us: |
| 157 | + |
| 158 | + |
| 159 | +``` |
| 160 | +curl -X POST 127.0.0.1:4001/commit \ |
| 161 | + --data @commit-request.json |
| 162 | +
|
| 163 | +``` |
| 164 | + |
| 165 | +This yields a large cbor blob which we can save to `commit-tx.json` file. |
| 166 | + |
| 167 | +Now we need to sign and submit the draft commit transaction. |
| 168 | + |
| 169 | +```shell |
| 170 | + |
| 171 | +cardano-cli transaction sign \ |
| 172 | + --tx-file commit-tx.json \ |
| 173 | + --signing-key-file hydra-cluster/config/credentials/alice-funds.sk \ |
| 174 | + --out-file signed-tx.json |
| 175 | + |
| 176 | + |
| 177 | +cardano-cli transaction submit \ |
| 178 | + --tx-file signed-tx.json \ |
| 179 | + --socket-path testnets/preprod/node.socket \ |
| 180 | + --testnet-magic 1 |
| 181 | +``` |
| 182 | + |
| 183 | +If we start the `hydra-tui` and wait a bit until the transaction we just sent is re-observed by the `hydra-node` we should see that the `Head` is now open. |
| 184 | + |
0 commit comments