Understanding total address currencies in order to perform simple transaction

It’s a while that I’m stuck here

I’m trying to perform a simple transaction from this address, which balance looks like:

cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 1097911063
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
63e9c27e39d07f89e774e8ce67c1dde00960cd0ce8a294446ef6e0710229f9c0    15        1400000 lovelace + 1 65b2b0dd9028c871ac1997399979cfc12a7f05738e1ec8d8a16ea52f.AadaGoldenTicket + TxOutDatumHashNone
67a0902d60e520007ba31046c7eaf2f4ef831d43e64e4dd94ae0417b71f56cb7     0        1000000000 lovelace + TxOutDatumHashNone
7d9ce3aecb2203c7c83277ac56cc910b38db597760a95efe65598bcd75bca838     1        989823279 lovelace + TxOutDatumHashNone

to be honest, I have no idea how to treat the AadaGoldenTicket token which I have here for some reason, so I tried every possible sum to calculate the total value in the address
using:

expr 1000000000 + 989823279
expr 1000000000 + 989823279 + 1400000

or even using cardano scan I should have 1,991.223279 tADA so in Lovelace

1991223279

what do I do:

cardano-cli transaction build-raw \
--tx-in 7d9ce3aecb2203c7c83277ac56cc910b38db597760a95efe65598bcd75bca838#1 \
--tx-out $(cat reciver.addr)+1000000000 \
--tx-out $(cat sender.addr)+0 \
--invalid-hereafter 0 \
--fee 0 \
--out-file toReciver.draft.txn \

#get fee

cardano-cli transaction calculate-min-fee \
--tx-body-file toReciver.draft.txn \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 \
--byron-witness-count 0 \
--testnet-magic 1097911063 \
--protocol-params-file testnet-protocol-params.json \

176897 Lovelace
#get current slot
cardano-cli query tip --testnet-magic 1097911063

#slot: 42946225
#input transaction params
cardano-cli transaction build-raw \
--tx-in 7d9ce3aecb2203c7c83277ac56cc910b38db597760a95efe65598bcd75bca838#1 \
--tx-out $(cat reciver.addr)+1000000000 \
--tx-out $(cat sender.addr)+$(expr 1000000000 + 989823279 - 1000000000 - 176897) \
--invalid-hereafter 42957225 \
--fee 176897 \
--out-file toReciver.raw.txn \

#sign
cardano-cli transaction sign \
--tx-body-file toReciver.raw.txn \
--signing-key-file sender.skey \
--testnet-magic 1097911063 \
--out-file toReciver.signed.txn \

#submit
cardano-cli transaction submit \
--tx-file toReciver.signed.txn \
--testnet-magic 1097911063 

I get any kind of UTxO error, which are not very helpful;

here is as an example the error message of the commands shown above:

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 989823279 (fromList [])) (Value 1991223279 (fromList [])))))])

which make me think that I’m getting wrong the way to calculate the total of the address; what should I do to get it right?

Hi!

The balance is worng:

–tx-out $(cat reciver.addr)+1000000000
–tx-out $(cat sender.addr)+$(expr 1000000000 + 989823279 - 1000000000 - 176897) \

You have in the UTXO 989823279 (989 ADA), then you don’t have enough funds to send 1000000000 (1000 ADA).

so in the utxo output only the last row is valid?

In my case, in the output:

cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 1097911063
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
63e9c27e39d07f89e774e8ce67c1dde00960cd0ce8a294446ef6e0710229f9c0    15        1400000 lovelace + 1 65b2b0dd9028c871ac1997399979cfc12a7f05738e1ec8d8a16ea52f.AadaGoldenTicket + TxOutDatumHashNone
67a0902d60e520007ba31046c7eaf2f4ef831d43e64e4dd94ae0417b71f56cb7     0        1000000000 lovelace + TxOutDatumHashNone
7d9ce3aecb2203c7c83277ac56cc910b38db597760a95efe65598bcd75bca838     1        989823279 lovelace + TxOutDatumHashNone

only

7d9ce3aecb2203c7c83277ac56cc910b38db597760a95efe65598bcd75bca838     1        989823279 lovelace + TxOutDatumHashNone

is the valid UTxO of the address?

thanks a lot for your response :smile:

Yes, each UTXO transaction represent an unspent balance in your account.

For example, you did 3 deposit transactions of 500 ADA each (your total balance is 1500 ADA):

UTXO#1 500 ADA
UTXO#2 500 ADA
UTXO#3 500 ADA

Now you want to send 750 ADA. You make a transaction with 2 TXins and 2 outs:

–tx-in UTXO#1
–tx-in UTXO#2
–tx-out $(cat reciver.addr)+750
–tx-out $(cat sender.addr)+(1000 - 750 - fee)

You use two UTXO with 1000 ADA, then you need to send you back the rest minus the fee ~250 ADA.

The problem in your case is that you are only using the last UTXO, transaction has less than 1000 ADA. That’s why, the transaction isn’t valid.

Regards.

1 Like

thanks @Juantxuthree , your explanation is very clear :heart_eyes:

1 Like