Need some help with a transaction to move NFT from one address to another. Keep getting ValueNotConservedUTxO

I’m stuck with this transaction. It doesn’t work for me. Keep getting ValueNotConservedUTxO error… when trying to move NFT from one address to another

Here is my first wallet addr_test1vr4td5a6wthnz3mu7er087fuvjgaz9d58qg243z34pl0g4qrqsh6y

e3dc31edbdda137bd8d7f0f65ec55adefa5c9da2f4b1cdfe37096090e87f3f01 #0
value: {
      lovelace: 997893577,
      '08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.CreateNewTOken': 1,
      '08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.ThisIsNewTOken': 1,
      '08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.hahaDaaddd': 1,
      '08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.mySupperCoolTokenNFT': 1,
      '08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.pokemon': 1,
      '8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.Hololo': 2,
      '8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.MyNewSuperTOken': 1,
      '8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.MyNewToken': 1,
      '8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.asdfasdf': 2,
}

This is My second wallet addr_test1vraext2hgj70q3skgy79p8f4mh47yxwj0e4twvmj7jmmhdcaxama8

   4938035c6898c887171c27ae7aa766207b5e3a54e4b73c7c6462ff1727d88522     0        999473357 lovelace + TxOutDatumHashNone

This the transaction that I’m trying to send:

[
  'cardano-cli',
  'transaction',
  'build-raw',
  '--fee',
  200000,
  '--tx-in e3dc31edbdda137bd8d7f0f65ec55adefa5c9da2f4b1cdfe37096090e87f3f01#0',
  '--tx-out',
  'addr_test1vr4td5a6wthnz3mu7er087fuvjgaz9d58qg243z34pl0g4qrqsh6y+996693577+"1 08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.ThisIsNewTOken"+"1 08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.hahaDaaddd"+"1 08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.mySupperCoolTokenNFT"+"1 08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.pokemon"+"2 8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.Hololo"+"1 8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.MyNewSuperTOken"+"1 8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.MyNewToken"+"2 8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d.asdfasdf"',
  '--tx-out',
  'addr_test1vraext2hgj70q3skgy79p8f4mh47yxwj0e4twvmj7jmmhdcaxama8+1000473357+"1 08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702.CreateNewTOken"',
  '--out-file',
  'policies/tmp/45767a4a-adce-47a9-a6c1-c76511ad2a52.raw'
]

Letter I’m executing it with join(’ '). so believe me the syntax is fine.
regarding the utxos:
my fee is 20000.
so the outputs are

  1. 997893577 - 200,000 - 1,000,000 = 996693577
    and
  2. 999473357 + 1,000,000 = 1000473357

But I keep getting ValueNotConservedUTxO

The full error:

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 997893577 (fromList [(PolicyID {policyID = ScriptHash "08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702"},fromList [("CreateNewTOken",1),("ThisIsNewTOken",1),("hahaDaaddd",1),("mySupperCoolTokenNFT",1),("pokemon",1)]),(PolicyID {policyID = ScriptHash "8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d"},fromList [("Hololo",2),("MyNewSuperTOken",1),("MyNewToken",1),("asdfasdf",2)])])) (Value 1997366934 (fromList [(PolicyID {policyID = ScriptHash "08eec649fbc016d2ddffb7b00ebe5fecca067749448de4f41a9dd702"},fromList [("CreateNewTOken",1),("ThisIsNewTOken",1),("hahaDaaddd",1),("mySupperCoolTokenNFT",1),("pokemon",1)]),(PolicyID {policyID = ScriptHash "8faa81397b2486b11bbf3ed4e71b7c83aaf5559059bf9042469acd2d"},fromList [("Hololo",2),("MyNewSuperTOken",1),("MyNewToken",1),("asdfasdf",2)])])))))])```

Answered this question in another topic:

Not sure where you got 999473357 from. That should be just 1000000 that you are sending with the tokens. But 1000000 is to small i think as you have custom token, go with something like 1.6ADA.

I guess 999473357 is the total funds from that address but you don’t need that here.

Oh… Now it make sense. I tried to add to the same UTXO of the receiver so I added 1000000 to his current balance instead of creating a new UTXO with just 1000000. I should ask that question before. killed about 3 hours trying to find what’s wrong. Thank you so much!

Np… so basically everything that is tx-in must be spent as part of fees and tx-out and you never include any totals from receiving addresses as that is handled by the protocol.

Hello!

I was wondering if you can shine some light over here! I have a transaction that includes 3 wallets which one is a payment address, the second one is the receiver of the tokens and a third wallet that receives a fee during the process.

deposit_address:
addr_test1vphnplepktk0wjvwdmm0vvddd9nj4w26xnrcx7jq506cz6gfgvzjm
(This has 3850000 lovelace in
a80c5766439febd8f9431da331f1a88f8828ff2cbf6c7ce2af425d4b82da8aa3)

sender (Payor):
addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60
(This should receive output + tokens)

extrawallet:
addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0
(This should receive 2 ADA)

cardano-cli transaction build-raw \

--tx-in a80c5766439febd8f9431da331f1a88f8828ff2cbf6c7ce2af425d4b82da8aa3#0 \

--tx-out addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60+1450000+"1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473" \

--tx-out addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0+2000000 \

--mint="1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C6647616E675265636F726473" \

--minting-script-file /policy.script \

--metadata-json-file /metadata.json \

--invalid-hereafter 49269192 \

--fee 200745 \

--out-file /matx.raw

When I try to submit the transaction I get this.

transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash "59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 3850000 (fromList [(PolicyID {policyID = ScriptHash "59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d"},fromList [("WolfGangRecords",1)])])) (Value 3649255 (fromList [(PolicyID {policyID = ScriptHash "59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d"},fromList [("Wolf&GangRecords",1)])])))))])

I know I’m missing substracting the fees from the output, but man Ive been trying in all sort of ways substracting from here and there and nothing! I even got to the point where the error shows Value 3850000 and Value 3850000 on the other side but still having the same error.

At this point I’m thinking I need to double the amount of fees and substract from both outputs idk I’m a bit lost at this point.

You can use build instead of build-raw, it’s much simpler and does not require fee calculation and output balancing:

$ cardano-cli transaction build \
  --tx-in a80c5766439febd8f9431da331f1a88f8828ff2cbf6c7ce2af425d4b82da8aa3#0 \
  --tx-out addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60+1450000+"1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473" \
  --change-address addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0 \
  --mint "1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C6647616E675265636F726473" \
  --minting-script-file policy.script \
  --metadata-json-file metadata.json \
  --witness-override 2 \
  --invalid-hereafter 49269192 \
  --out-file matx.raw

should work and just put everything that’s left into addr_test1vz5y...skehf0.

Also: The ScriptWitnessNotValidatingUTXOW looks like you forgot one of the two signatures. This has to be signed by both, the owner of the --tx-in (named payment.skey in most tutorials) and the key given in the policy script (named policy.skey in most tutorials). That’s why --witness-override 2 is in that command.

Edit: Just realised you wanted that extra wallet to only get a specific amount. But then the rest is not enough to go back into the payment wallet (has to be at least 1 (t)ADA). If the payer and the extra wallet, really should not get more than 1.45 and 2.0 (t)ADA, we would need more input, put them both in explicit --tx-outs and put addr_test1vphn...fgvzjm as --change-address that receives the rest.

Thank you man, lets begin there. I’m sorry for the confusion with file directories. I modified the original edit with the directory paths so that it makes sense.

I actually did try with transaction build, its way easier and was able to get the response you pointed out with the unbalance utxo missing a small lovelace. I think I need to increase the output with that difference to the wallet that has tokens.

Ill will run some test later today

OK after testing only the transaction without minting I was able to succesfully submitted by adding the difference to the ouput of the Payor, but now fails if I try to add metadata and tokens for minting…

cardano-cli transaction build \
> --testnet-magic 1097911063 \
> --tx-in a80c5766439febd8f9431da331f1a88f8828ff2cbf6c7ce2af425d4b82da8aa3#0 \
> --tx-out addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60+1656779+"1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473" \
> --tx-out addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0+2000000 \
> --change-address addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60 \
> --mint="1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C6647616E675265636F726473" \
> --minting-script-file /policy.script \
> --metadata-json-file /metadata.json \
> --invalid-hereafter 49269192 \
> --witness-override 1 \
> --out-file /matx.raw

This is what I get

transaction build  Error: Non-Ada assets are unbalanced: -1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576f6c662647616e675265636f726473 + 1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576f6c6647616e675265636f726473

Looks like the minting section is not being balanced in the transaction but it seems fine to me, I’m probably missing something stupid…

Ohh! just realized the names are different! Wow! of course is unbalanced…

59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473

vs

59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C6647616E675265636F726473

The asset names are different
576F6C662647616E675265636F726473
576F6C6647616E675265636F726473

I didn’t realized about the difference in the base16 encoded string!

… After fixing I got the witness count errorrs… How do I know how many witness I need to set?

 transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash "59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d"])))])

As far as I understood it: It is just the number of signatures that you will give to the transaction (and it is just needed, because it changes the fees, because it changes the size of the transaction).

If it is just one (all --tx-ins belong to the same key and that’s the only signature), we don’t have to give a value, there. But it’s two in this case, the payment/minting/deposit key and the key of the policy.

And they both also have to be given in the transaction sign step.

Ok I see. Well in this case the --tx-in that are coming in exists in one wallet only (deposit_address) then its 1 Witness only am I right? With only one payment key at the time of signing, which is the the reason I was using one witness.

Maybe I should remove the witness override because I’m using 1?

No:

You are minting, aren’t you? And nearly all guides use another key for the policy.

Yes correct I’m minting a token but I want to mint the token in the sender wallet which I’m also sending the output. The payor of the transaction its the deposit_address with the available funds.

deposit_address has the funds and payment keys => 3.85 --tx-in
addr_test1v…

sender_address receives the 1656779 (output) + token
addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60

extra_wallet receives 2 ADA
addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0

And the key of deposit_address is also the key for the key hash given in policy.script? In that case you really only need one witness.

Yes correct, the policy ids its made with the same key. Let’s say I made the mistake while producing the policy manually. I’d like to know if that was the case or if I’m missing something else regarding the witness signatures.

I’ll run more tests later today. I’ll post something over here

1 Like

I don’t necessarily consider that a mistake. Was in fact asking myself, why everybody uses several keys if they end up in the same directory structure, anyway.

Yes, the whole concept is that if you have the key for the policy which was created with the keys of the wallet, then you can sign the transaction. This is the witness that is adding funds into the transaction as my understanding, I could be wrong hehe

Circling back to this issue that I was having when building the transaction. It may help somebody in the future. After looking at the source code of Cardano Cli. Witnesses are wallets that are adding unspent transactions --tx-in , and therefore these will need sign the transaction.

From Cardano-node source code Commands file

   -- | Like 'TxBuildRaw' but without the fee, and with a change output.
  | TxBuild
      [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
      -- ^ Required signers

For this transaction we only need one witness because there’s one wallet paying for the transaction.

cardano-cli transaction build \
> --testnet-magic 1097911063 \
> --tx-in a80c5766439febd8f9431da331f1a88f8828ff2cbf6c7ce2af425d4b82da8aa3#0 \
> --tx-out addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60+1656779+"1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473" \
> --tx-out addr_test1vz5y5uflj7wzpqkpz6uhdxqgkdgz48esvenyr3zcxy0jcyqskehf0+2000000 \
> --change-address addr_test1vqycal0wrl34j935gypcxvha5mw8crf0csz6ye9j9cv7huscfyh60 \
> --mint="1 59beb5ca56974adf2a6976ed9bcc1f5a6b99b7ed08b76a8f4bc60a7d.576F6C662647616E675265636F726473" \
> --minting-script-file /policy.script \
> --metadata-json-file /metadata.json \
> --invalid-hereafter 49269192 \
> --witness-override 1 \
> --out-file /matx.raw

The Error
As noted before, I made a mistake when copying the base16 encoded asset name when it was been added for minting in the transaction, therefore the transaction would have been unbalanced. Basically this happens when you’re trying to mint an asset A but you’re outputting Asset B to the receiver wallet, meaning that when I fixed the asset name for both to be the same asset name, the transaction was fixed.

Human error on this transaction
Every policy and transaction is generated with specific values like the invalid slot, the metadata, policy keys and hash. If by any reason these values changes during the transaction process, the transaction may be unbalanced or even using the wrong amount of witnesses therefore failing in the process.

The Real Fix for one to many wallets

Any funds from unspent transaction that goes in, must go out as change or output. What this means is that you either spend it ( Wisely :slight_smile: ) or you can return it. Keep in mind that the minimum to create a transaction is 1 ADA, so if the change is less than that you MUST spend it somewhere else (Either increasing the output sent in the tokens or increasing the change). If its more than 1 ADA you can add another --tx-0 (Many wallets) or leave it for change! :tada: