Skip to main content

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:

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 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:

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 \
--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:

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

The transation will now be validated by all connected hydra-nodes 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.