0

I recently wrote some scripts that mint and send tokens. When I run the script to mint a token and then immediately run the script to send that token to a wallet, I get this error:

Error: Command failed: cardano-cli transaction submit --testnet-magic 1097911063 --tx-file ./tmp/tx_n5sm4btig.signed
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationErrorShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 0 (fromList [(PolicyID {policyID = ScriptHash "1a1b09e939ec7fd1b60c1e4d71808926421079f679e79d1e9f36561a"},fromList [("TestNFT",1)])])) (Value 992262587 (fromList [(PolicyID {policyID = ScriptHash "1a1b09e939ec7fd1b60c1e4d71808926421079f679e79d1e9f36561a"},fromList [("TestNFT",1)]),(PolicyID {policyID = ScriptHash "584af528f36789c8d5cc9336ec258326cbea8b3983d9d6d40cdc5bce"},fromList [("TestNFT",1)]),(PolicyID {policyID = ScriptHash "6eee44f15e11b84d33bcaaff8096d36fa400f6cb8eaa14007d6fac1b"},fromList [("TestNFT",1)]),(PolicyID {policyID = ScriptHash "b294451d861bc02b49591d9413a12f8b24a0f17c57940c9d78d1074c"},fromList [("TestNFT",1)]),(PolicyID {policyID = ScriptHash "e7ba14bfcb30f171b106ea15984cd25101d73f72fc89f2bb864ff600"},fromList [("TestNFT",1)])]))))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (BadInputsUTxO (fromList [TxIn (TxId {_unTxId = SafeHash "7d667aef6319a22a71903fca4d88b69cea24e23c36120e11f34738aa8d90da07"}) 0]))))])

A similar error happens if I run the script to mint a token and then immediately re-run it. It seems like rapid back-to-back transactions cause this. Am I doing something incorrectly?

Edit: I wanted to add that the scripts work as expected if there is a pause (>~1 minute) between each execution.

Any help is appreciated, and I apologize if this is a basic question!

1 Answer 1

0

Basically, the error ValueNotConservedUTxO means that your transaction is not balanced. Take a look on this answer to follow the appropiate process to submit transactions.

Other points to consider:

  1. Depending how you're building and submitting your transactions, but consider that your transactions need to be confirmed in order to get your UTxOs updated.

  2. When I run the script to mint a token and then immediately run the script to send that token to a wallet, I get this error

  • You can't mint a NFT and send it immediately in another transaction because you need to wait until the first transaction (your NFT) get reflected on your UTxOs
  • But you can mint and send the NFT in the same transaction. I think this is the best approach.
    cardano-cli transaction build-raw \
    --fee <fee> \
    --tx-in <tx_in> \
    --tx-out <your_address>+<change> \
    --tx-out <destination_address>+<minUtxO>+1 <nft> \
    --mint=1 <nft> \
    --minting-script-file <policy-file> \
    --metadata-json-file <metadata-file> \
    --invalid-hereafter=<slot> \
    --out-file <outputfile.raw>
  1. A similar error happens if I run the script to mint a token and then immediately re-run it.

  • Consider that your UTxOs get re ordered every time you submit a transaction.
1
  • 1
    This was very helpful; thank you. The problem was related to UTxOs not being updated, as you said. I'll attempt to mint and send in the same transaction and see how it goes.
    – sdub
    Dec 3, 2021 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.