Commit funds to an open Head
Assuming we already have an open Head and some funds on the L1 we would like to commit.
You could run a local demo
The following commands are expected to be run from the demo
folder and using these environment variables:
export CARDANO_NODE_SOCKET_PATH=${PWD}/devnet/node.socket
export CARDANO_NODE_NETWORK_ID=42
We can inspect the L1 utxo with:
cardano-cli query utxo --whole-utxo
and the state of the faucet public key
cardano-cli query utxo \
--address $(cardano-cli address build --payment-verification-key-file ${PWD}/../hydra-cluster/config/credentials/faucet.vk)
In this setup, we would be using the faucet
keys to commit everything into the head.
export WALLET_SK=${PWD}/../hydra-cluster/config/credentials/faucet.sk
export WALLET_VK=${PWD}/../hydra-cluster/config/credentials/faucet.vk
Deposit UTxO to commit
The /commit
endpoint supports two ways of specifying what to commit, one is just by showing the UTxO (which is assumed to be owned by public keys), while the more advanced way would be using blueprint transactions.
We are using the simple request here and want to commit everything owned by ${WALLET_SK}
. So we can just query the L1 for all UTxO owned by it:
cardano-cli query utxo \
--address $(cardano-cli address build --payment-verification-key-file ${WALLET_VK}) \
--out-file commit-utxo.json
Then a request to the /commit
endpoint provides us with a transaction:
curl -X POST localhost:4001/commit \
--data @commit-utxo.json \
> deposit-tx.json
Which we can submit to the cardano network:
cardano-cli transaction sign \
--tx-file deposit-tx.json \
--signing-key-file ${WALLET_SK} \
--out-file deposit-tx.signed.json
cardano-cli transaction submit \
--tx-file deposit-tx.signed.json
This will result in a deposit being detected by the hydra-node
and consequently the funds to be committed to the head.
Recover a deposit
Do the same thing as above, but with one node stopped, so the deposit is not going to be picked up.
Once we deposited funds we should not see the corresponding UTxO belonging to faucet public key on L1:
cardano-cli query utxo \
--address $(cardano-cli address build --payment-verification-key-file ${PWD}/../hydra-cluster/config/credentials/faucet.vk)
Inspect the pending deposits:
curl -X GET localhost:4001/commits
and you should see the tx-id of the deposit transaction ["6b51f3787f5482004b258c60fe0c94775164f547d9284b6233bbb4f6f8b9dfa6"]
To recover, we can use the /commits
endpoint again using the transaction id of the deposit:
curl -X DELETE localhost:4001/commits/$(printf "\"6b51f3787f5482004b258c60fe0c94775164f547d9284b6233bbb4f6f8b9dfa6"\" | jq -sRr '@uri')
If we inspect the faucet funds again we will see that the locked deposit is now recovered
cardano-cli query utxo \
--address $(cardano-cli address build --payment-verification-key-file ${PWD}/../hydra-cluster/config/credentials/faucet.vk)