Especially if you are writing a walk-through for beginners, please advise them to use build
instead of build-raw
. It’s a PITA debugging all those cases, where the balances don’t add up.
The old way:
$ cardano-cli query utxo --mainnet --address addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq
TxHash TxIx Amount
--------------------------------------------------------------------------------------
82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158 0 13933006 lovelace + TxOutDatumNone
82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158 1 4000000 lovelace + 10000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e + TxOutDatumNone
$ cardano-cli transaction build-raw \
> --tx-in 82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158#1 \
> --tx-out "addr1q89vv6r6e7040j7lm5m3s9c9cv7l0hdchwrwt62xm4v7h2df36408rhdrmchm7pxj8huuyz4jsgzqjllta5xfgrjysqsznluu4+2000000+3000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --tx-out "addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq+2000000+7000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --fee 200000 \
> --out-file trans1-tx.raw
$ cardano-cli query protocol-parameters --mainnet --out-file protocol.json
$ cardano-cli transaction calculate-min-fee --mainnet \
> --tx-body-file trans1-tx.raw \
> --tx-in-count 1 --tx-out-count 2 --witness-count 1 \
> --protocol-params-file protocol.json
179845 Lovelace
$ cardano-cli transaction build-raw \
> --tx-in 82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158#1 \
> --tx-out "addr1q89vv6r6e7040j7lm5m3s9c9cv7l0hdchwrwt62xm4v7h2df36408rhdrmchm7pxj8huuyz4jsgzqjllta5xfgrjysqsznluu4+2000000+3000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --tx-out "addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq+1820155+7000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --fee 179845 \
> --out-file trans1-tx.raw
$ cardano-cli transaction sign --mainnet \
> --tx-body-file trans1-tx.raw \
> --signing-key-file ../mint.skey \
> --out-file trans1-tx.signed
$ cardano-cli transaction submit --mainnet --tx-file trans1-tx.signed
Transaction successfully submitted.
We have to download protocol parameters, calculate the minimal fee by hand, adjust the outputs, …
Especially if people use the army of shell variables used for some reason in a lot of guides, there are so many places, where something can go wrong.
The “new” way:
(in fact, not so new at all)
$ cardano-cli query utxo --mainnet --address addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq
TxHash TxIx Amount
--------------------------------------------------------------------------------------
38c6e56642afdbe796414271834c092f8481b68c3fd97d36348ccbda535f0176 1 1820155 lovelace + 7000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e + TxOutDatumNone
82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158 0 13933006 lovelace + TxOutDatumNone
$ cardano-cli transaction build --mainnet \
> --tx-in 38c6e56642afdbe796414271834c092f8481b68c3fd97d36348ccbda535f0176#1 \
> --tx-in 82ad4e06c9a7319e765114aa15910a46391a1bc23900d808deeb86315c1ae158#0 \
> --tx-out "addr1q89vv6r6e7040j7lm5m3s9c9cv7l0hdchwrwt62xm4v7h2df36408rhdrmchm7pxj8huuyz4jsgzqjllta5xfgrjysqsznluu4+2000000+3000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --tx-out "addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq+2000000+4000 a80398fd0dd6c71bbe067f6181274d0d9aff81d351d8c6749d6581dd.c39e6f7220436f696e" \
> --change-address addr1vxlgahj760v86tzcpr5xd9u80kcmgm2gsl6ulhvxnya26pq3h39nq \
> --out-file trans2-tx.raw
Estimated transaction fee: Lovelace 178657
$ cardano-cli transaction sign --mainnet \
> --tx-body-file trans2-tx.raw \
> --signing-key-file ../mint.skey \
> --out-file trans2-tx.signed
$ cardano-cli transaction submit --mainnet --tx-file trans2-tx.signed
Transaction successfully submitted.
No fee calculation by hand, no balancing of ADA by hand, no download of protocol parameters, the rest just flows into a UTxO at the given --change-address
.
(Note: Unfortunately, non-ADA assets still have to be balanced by hand up to now. Otherwise we could have saved one --tx-out
to the --change-address
itself in this command.)