Problems with generating a staking delegation transaction via cardano-cli

I am having trouble generating and sending a stake delegation transaction via cardano-cli. Currently, I am following this manual, kindly recommended by @Alexd1985 and some other forum members. I’ve listed the commands I am running and the error (related to the UTXO) below:

  1. Query the UTXO:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli query utxo     --address $(cat payment.addr)     --testnet-magic ${TESTNET_MAGIC}
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
b23dc64d41bfef44c01345c5cbf13b9f6f3ab1d3a517283b1953807d2c52e35b     0        969569464 lovelace + TxOutDatumHashNone
  1. Generate a certificate for the pool id:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli stake-address delegation-certificate     \
        --stake-verification-key-file /user/stake.vkey     \
        --stake-pool-id 8b5060d437571746f57cbd27dab89eb8e6045a554919dc472748920c     \
        --out-file /user/deleg.cert
  1. Generate a dummy tx for calculating fee:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli transaction build-raw \
        --tx-in b23dc64d41bfef44c01345c5cbf13b9f6f3ab1d3a517283b1953807d2c52e35b#0 \
        --tx-out $(cat payment.addr)+969569464  \
        --fee 0 \
        --certificate-file /user/deleg.cert \
        --out-file /user/stake.tx.tmp
  1. Calculate the fee:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli transaction calculate-min-fee \
        --tx-body-file /user/stake.tx.tmp \
        --tx-in-count 1 \
        --tx-out-count 1 \
        --witness-count 2 \
        --byron-witness-count 0 \
        --protocol-params-file /user/protocol.json  \
        --testnet-magic ${TESTNET_MAGIC}
180549 Lovelace
  1. Calculate the output. Note I want to delegate 10 ADA:
ubnutu@nodes-ubuntu:~/cardano$ expr 969569464 - 180549 - 10000000
959388915
  1. Build the transaction to be sent:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli transaction build-raw \
        --tx-in b23dc64d41bfef44c01345c5cbf13b9f6f3ab1d3a517283b1953807d2c52e35b#0 \
        --tx-out $(cat payment.addr)+959388915 \
        --fee 180549 \
        --certificate-file /user/deleg.cert \
        --out-file /user/stake.tx
  1. Sign the tx:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli transaction sign \
        --tx-body-file /user/stake.tx \
        --signing-key-file /user/payment.skey \
        --signing-key-file /user/stake.skey \
        --testnet-magic ${TESTNET_MAGIC} \
        --out-file /user/stake.signed
  1. And eventually submit:
ubnutu@nodes-ubuntu:~/cardano$ cardano-cli transaction submit \
        --tx-file /user/stake.signed --testnet-magic ${TESTNET_MAGIC}
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 969569464 (fromList [])) (Value 959569464 (fromList [])))))])

What do I miss?

There lies the error. You delegate an entire wallet, whatever ada it contains.

Your transaction out should therefore be initial utxo minus fees. That’s it.

Please note that in order to delegate, your stake key must be registered first. Just in case.

1 Like

Oh, for some reason I thought I could specify the amount to delegate.
After I fixed it, it worked. Thank you @Psychomb !