Issue when transferring tokens

I am trying to transfer some tokens and NFTs from the pool account to an external account. When trying to do so I get the following error:

**Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (ValueNotConservedUTxO (Value 72719983 (fromList [])) (Value 72719983 (fromList [(PolicyID {policyID = ScriptHash "7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6"},fromList [(434e43416c61,100)])])))))])**

I checked and all is working correctly when sending some ADA only but when trying to send any token I get this error. The commands I am using are as follows:

**#Producer Environment**
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
echo Current Slot: $currentSlot
amountToSend=3000000 #sending also 3 ADA
echo amountToSend: $amountToSend
destinationAddress=<destinationAddress>
echo destinationAddress: $destinationAddress

cardano-cli query utxo \
--address $(cat keys/keys-payment/payment.addr) \
--mainnet > keys/keys-payment/fullUtxo.out
tail -n +3 keys/keys-payment/fullUtxo.out | sort -k3 -nr > keys/keys-payment/balance.out
cat keys/keys-payment/balance.out
tx_in=""
total_balance=0
while read -r utxo; do
type=$(awk '{ print $6 }' <<< "${utxo}")
if [[ ${type} == 'TxOutDatumNone' ]]
then
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
idx=$(awk '{ print $2 }' <<< "${utxo}")
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
total_balance=$((${total_balance}+${utxo_balance}))
echo TxHash: ${in_addr}#${idx}
echo ADA: ${utxo_balance}
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
fi
done < keys/keys-payment/balance.out
txcnt=$(cat keys/keys-payment/balance.out | wc -l)
echo Total available ADA balance: ${total_balance}
echo Number of UTXOs: ${txcnt}

cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat keys/keys-payment/payment.addr)+**0** \
--tx-out ${destinationAddress}+"100 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61" \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee 0 \
--out-file keys/keys-payment/tx.tmp
cardano-cli query protocol-parameters \
--mainnet \
--out-file keys/keys-payment/protocol.json

fee=$(cardano-cli transaction calculate-min-fee \
--tx-body-file keys/keys-payment/tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 2 \
--mainnet \
--witness-count 1 \
--byron-witness-count 0 \
--protocol-params-file keys/keys-payment/protocol.json | awk '{ print $1 }')
echo fee: $fee
txOut=$((${total_balance}-${fee}-${amountToSend}))
echo Change Output: ${txOut}

cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat keys/keys-payment/payment.addr)+${txOut} \
--tx-out ${destinationAddress}+${amountToSend}+"100 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61" \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee ${fee} \
--out-file keys/keys-payment/tx.raw

**# Copy tx.raw to your Offline environment.**

**# Script # Offline #**
cardano-cli transaction sign \
--tx-body-file keys/keys-payment/tx.raw \
--signing-key-file keys/keys-payment/payment.skey \
--mainnet \
--out-file keys/keys-payment/tx.signed

**# Copy tx.signed to your producer environment.**
**# Script # Producer Node #**
cardano-cli transaction submit \
--tx-file keys/keys-payment/tx.signed \
--mainnet

Any idea what I might be doing wrong? Thank you for your help.

did u check first the UTXOs from wallet?

There are many other posts with solution for ur error

https://forum.cardano.org/search?context=topic&context_id=116884&q=ValueNotConservedUTxO&skip_context=true

Cheers,

Yes, I checked the other issues but still, I do not know what might be the issue in my case. The wallet balance.out is:

b01a2e8582ce7ae7b8eff2e44119fe7aefdb858e9ddd47abff3d5f4489940f1a 0 72719983 lovelace + TxOutDatumNone
5990c41a6074433ef4c4906e0c181492746b0de9544e0c067a8285a32dcbd7d6 2 1827440 lovelace + 3128 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61 + 1000000000 af2e27f580f7f08e93190a81f72462f153026d06450924726645891b.44524950 + 5000000 b6a7467ea1deb012808ef4e87b5ff371e85f7142d7b356a40d9b42a0.436f726e75636f70696173205b76696120436861696e506f72742e696f5d + TxOutDatumNone
221b8615d0c4d7a79265457f217d329db329284067ab05fbf370b31ea1afa01e 2 1344720 lovelace + 1034 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61 + TxOutDatumNone
b0c6189f24c5f4a062d2d10241ce804bfd6c8a4126e3b7360075a9ba6072256f 0 1155080 lovelace + 1000000 af2e27f580f7f08e93190a81f72462f153026d06450924726645891b.44524950 + TxOutDatumNone
d0df955950e6518a084004c62c2665ba88cda3f498bc2ebd90ef7270ed2c0e28 0 1146460 lovelace + 1 f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a.63656e74756f + TxOutDatumNone

And the TXN_IN in the above code is: TxHash: b01a2e8582ce7ae7b8eff2e44119fe7aefdb858e9ddd47abff3d5f4489940f1a#0

in this case, I have:

cardano-cli transaction build-raw
${tx_in}
–tx-out $(cat keys/keys-payment/payment.addr)+${txOut}
–tx-out ${destinationAddress}+${amountToSend}+“100 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61”
–invalid-hereafter $(( ${currentSlot} + 10000))
–fee ${fee}
–out-file keys/keys-payment/tx.raw

where:

tx-in = 72719983 (tx_in balance)

tx-out = 72719983 (tx_in balance) - 185653 (fee) - 3000000 (amount to send) = 69534330

tx-out = 3000000 (amount to send) + 100 tokens

I can see that in this TXN_IN there is enough ADA to perform the transaction and the sum of INs are the same as sum of OUTs + fee?, correct me if I am wrong. Not sure what is happening in my case. Any idea? Thank you.

fist, did u try to send only few ADA for test to check if this way the transaction is working?

1 Like

Yes with only ADA is working fine, but when trying to send the tokens I get the above error. I can see tx-in = tx-out1 + tx-out2 + fee:

tx-in = 72719983 (tx_in balance)

tx-out1 = 72719983 (tx_in balance) - 185653 (fee) - 3000000 (amount to send) = 69534330 (which is the refund to source address)

tx-out2 = 3000000 (amount to send) + 100 tokens = 3000000 (which is what I send to the destination address)

tx-out1 + tx-out2 + fee = 69534330 + 3000000 + 185653 = 72719983 which is the same as tx-in

Not sure what I am doing wrong when sending the tokens.

Even after increasing fee to 200569, I am still getting the same error:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (ValueNotConservedUTxO (Value 72719983 (fromList )) (Value 72719983 (fromList [(PolicyID {policyID = ScriptHash “7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6”},fromList [(434e43416c61,100)])])))))])

It is working now. You need to add to the TX-IN also the token or NFT you are sending:

cardano-cli transaction build-raw
–tx-in b01a2e8582ce7ae7b8eff2e44119fe7aefdb858e9ddd47abff3d5f4489940f1a#0
–tx-in 5990c41a6074433ef4c4906e0c181492746b0de9544e0c067a8285a32dcbd7d6#2
–tx-out $(cat keys/keys-payment/payment.addr)+${txOut}
–tx-out ${destinationAddress}+${amountToSend}+“3128 7ab95d389c9237edfb0305fc889825ea4221e82a78446b3c78c0d5b6.434e43416c61”
–invalid-hereafter $(( ${currentSlot} + 10000))
–fee ${fee}
–out-file keys/keys-payment/tx.raw

1 Like