Skip to content

Commit

Permalink
Convert and fix instructions how to submit a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed May 8, 2024
1 parent 96ba5a9 commit c46c2f9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
34 changes: 0 additions & 34 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,6 @@ The `hydra-node` is compatible with the Cardano `mainnet` network, and can conse

TODO integrate https://github.com/input-output-hk/hydra/pull/1414

## Generating transactions for the WebSocket API

To perform a transaction within an initialized Head via the WebSocket API of Hydra Node, use the commands below and send the output to the node:

```bash title="Transaction building"
cardano-cli transaction build-raw \
--babbage-era \
--tx-in 09d34606abdcd0b10ebc89307cbfa0b469f9144194137b45b7a04b273961add8#687 \
--tx-out addr1vx8apm8x8rla2w6tk7dxnwrlxkmeuera4x4tw5j695xhxeq4wawpz+7620669 \
--fee 0 \
--out-file tx.json

cardano-cli transaction sign \
--tx-body-file tx.json \
--signing-key-file cardano.sk \
--out-file signed-tx.json

echo "{ \"tag\": \"NewTx\", \"transaction\": $(cat signed-tx.json | jq ".cborHex") }"
{ "tag": "NewTx", "transaction": "84a3008182582009d34606abdcd0b10ebc89307cbfa0b469f9144194137b45b7a04b273961add81902af0181a200581d618fd0ece638ffd53b4bb79a69b87f35b79e647da9aab7525a2d0d7364011a0074483d0200a10081825820c736d40ee64c031851af26007c00a3b6fcbebccfd333a8ee6f14983f9be5331c58404bae506f5235778ec65eca6fdfcf6ec61ab93420b91e0b71ca82d437904f860e999372cf00252246ca77012e19c344b3af60df9f853af53fc86835f95a119609f5f6" }
```
The `--tx-in` value is a UTxO obtained from the `GET /snapshot/utxo` request. For example:
```json title="Example response of GET /snapshot/utxo"
{
"09d34606abdcd0b10ebc89307cbfa0b469f9144194137b45b7a04b273961add8#687": {
"address": "addr1w9htvds89a78ex2uls5y969ttry9s3k9etww0staxzndwlgmzuul5",
"value": {
"lovelace": 7620669
}
}
}
```
## Example Setup

### Google Cloud w/ Terraform
Expand Down
52 changes: 52 additions & 0 deletions docs/docs/how-to/submit-transaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Submit a transaction

To submit a transaction to an already open Head, you need to use `NewTx` command of the WebSocket API.

First, let's query the UTxO available in the head:

```
curl localhost:4001/snapshot/utxo | jq
```

An example response could look like:

```json title="Example response of GET /snapshot/utxo"
{
"8690d7618bb88825d6ec7cfbe2676779b8f4633cb137a1c12cd31b4c53f90f32#0": {
"address": "addr_test1vrdhewmpp96gv6az4vymy80hlw9082sjz6rylt2srpntsdq6njxxu",
"datum": null,
"datumhash": null,
"inlineDatum": null,
"referenceScript": null,
"value": {
"lovelace": 100000000
}
}
}
```

Assuming the single utxo is owned by `some-payment-key.sk` and we want to send all of it to some other address, we can use the `cardano-cli` (or your favorite transaction builder) to construct and sign a transaction:

```shell title="Transaction building"
cardano-cli transaction build-raw \
--babbage-era \
--tx-in 8690d7618bb88825d6ec7cfbe2676779b8f4633cb137a1c12cd31b4c53f90f32#0 \
--tx-out addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z+100000000 \
--fee 0 \
--out-file tx.json

cardano-cli transaction sign \
--tx-body-file tx.json \
--signing-key-file some-payment-key.sk \
--out-file tx-signed.json

cat tx-signed.json | jq -c '{tag: "NewTx", transaction: .}'
```

This will output a message that can be submitted to a websocket connection to `hydra-node`. Using `websocat` and assuming the `hydra-node` runs on the default port `4001` we can submit with:

```shell
cat tx-signed.json | jq -c '{tag: "NewTx", transaction: .}' | websocat "ws://127.0.0.1:4001?history=no"
```

The transation will now be validated by all connected `hydra-node`s and either result in a `TxInvalid` message with a reason, or a `TxValid` message and a `SnapshotConfirmed` with the new UTxO available in the head shortly after.
2 changes: 1 addition & 1 deletion docs/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ will print the `NewTx` command to copy paste into an already open websocket
connection:

```shell
cat tx-signed.json | jq -c '{tag: "NewTx", transaction: .cborHex}'
cat tx-signed.json | jq -c '{tag: "NewTx", transaction: .}'
```

The transation will be validated by both `hydra-node`s and either result in a
Expand Down

0 comments on commit c46c2f9

Please sign in to comment.