-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert and fix instructions how to submit a transaction
- Loading branch information
Showing
3 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters