Transaction submission error

Hi everyone,

When I execute the transaction command cardano-cli transaction submit --tx-file matx.signed --testnet-magic $TESTNET_ID I get the following error:

Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 20000000 (fromList [(PolicyID {policyID = ScriptHash "20237e7483411cd8f5c5b8edd83bd6d4f4732471604b4f4bbcc9f285"},fromList [("Test",1)])])) (Value 21824159 (fromList [(PolicyID {policyID = ScriptHash "20237e7483411cd8f5c5b8edd83bd6d4f4732471604b4f4bbcc9f285"},fromList [("Test",1)])])))))])

I hard coded the fee to 20000000 lovelace. Could this be causing the error?
Also tried using the calculate-min-fee but the transaction was still failing.

Following up on my question. I built the transaction using the following commands:

cardano-cli transaction build-raw \ --fee 2000000 \ --tx-in $TX_HASH#$TX_IX \ --tx-out $(< payment.addr)+$(($AVAILABLE_LOVELACE - $TX_FEE))+"$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \ --mint="$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \ --minting-script-file policy/policy.script \ --metadata-json-file metadata.json \ --invalid-hereafter $SLOT \ --out-file matx.raw
and
cardano-cli transaction sign \ --signing-key-file payment.skey \ --signing-key-file policy/policy.skey \ --testnet-magic $TESTNET_ID \ --tx-body-file matx.raw \ --out-file matx.signed

The error means that TX-IN, TX-OUT, fee, minted tokens do not match…

So basically everything that is part of the TX-IN UTXOs must be spent as part of the fee and TX-OUT. Also the minted tokens must be part of TX-OUT.

So you need to examine the tx-in UTXO and make sure you “spend” all the tokens contained in that(those) utxo(s).

From the error it seems like token 20237e7483411cd8f5c5b8edd83bd6d4f4732471604b4f4bbcc9f285 from the utxo is not part of tx-out.

Makes sense, however I still don’t understand what I need to add/change.

cardano-cli transaction build-raw \ --fee 2000000 \ --tx-in $TX_HASH#$TX_IX \ --tx-out $(< payment.addr)+$(($AVAILABLE_LOVELACE - $TX_FEE))+"$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \ --mint="$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \ --minting-script-file policy/policy.script \ --metadata-json-file metadata.json \ --invalid-hereafter $SLOT \ --out-file matx.raw

Under the flag --tx-out I have specified $(< policy/policyId).$TOKEN_NAME
$(< policy/policyId) equals 20237e7483411cd8f5c5b8edd83bd6d4f4732471604b4f4bbcc9f285
Shouldn’t this be sufficient?

Does $TX_FEE equal 2000000? Asking as you have the fee hard coded.

Yes it does

hmm… can you anyhow relate these two numbers from the error 21824159 and 20000000?

How many tokens are you minting?
How much ADA are going to the destination address alongside the minted tokens?

Also maybe give us the tx-in utxo.

No idea where 21824159 is coming from. Where can I see the additional ADA being sent alongside with the token?

--tx-in c73914f7d6d215ad69d8d5f5e0049d54aeee62dad05c5a905860d89505caca93#0

--tx-out addr_test1vq4eu8c2lvyqd74wyxnvv4hv3t2p67e8s8kfy4225lydzug6a9jju+19824159+"1 6719bb84cfa7bb8eee6f4b349e44423bb573e7da8dc1bd820ac797f5.Test"

Please send output of:

cardano-cli query utxo --testnet-magic $TESTNET_ID --address addr_test1vq4eu8c2lvyqd74wyxnvv4hv3t2p67e8s8kfy4225lydzug6a9jju

I meant the ADA that goes to the destination address together with the custom token. In this case 19824159.

Here it is:

                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
c73914f7d6d215ad69d8d5f5e0049d54aeee62dad05c5a905860d89505caca93     0        20000000 lovelace + TxOutDatumHashNone

Btw the utxo has 20ADA. You declared the fee to be 2ADA but you are sending 19.824159ADA to your payment address which doesn’t seem right.