<p><code>BadInputsUTxO</code> means the input UTxO doesn't exist. It may have existed previosuly and has since been spent. Query the ledger state for current UTxOs and make sure to update your <code>$txin</code> accordingly.</p>

CC BY-SA 4.0
2023-03-14T15:00:56.717Z
I'm confuse because the $txin is of the smart contract and is this: 

e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad#0

You can view it here: 

https://preview.cardanoscan.io/address/70919d457eac2f4e68d6835f8643852b51f7eecc7a2a9cd31d0944b24b

So the tx does indeed exist i think or could be expent (?)
ash
CC BY-SA 4.0
2023-03-15T10:19:44.473Z
It's complaining about `18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225#1` that I can confirm is not in the ledge state. Whats's `$collateral`?
james
CC BY-SA 4.0
2023-03-15T16:35:42.130Z
Yes it is complaining about that utxo but the input was set with an id #0.
I did the bash script again with another inputs this time, and results in an error with either of the $txin locked in the contract:
a2a5f6a632d62bac847631b90749b11f43a2d861f8cd9c6bb3e7a4e0b7c64ca9#0
f3adbc5cd55a7473bfd12e944982f372282b12ba4611cf1293891b77f2b7a43a#0
and the collateral is:
a5ff5ca6ef0525dd1eb337f8a385dfbd4715288f5bc47a76e44ad28eba9caffd#0
And then is ix complaining about with the last utxo at index #1, and that utxo doesn't exist at #1 just at #0 :S (whatever of both txin I use as an input $txin):
ash
CC BY-SA 4.0
2023-03-15T16:35:48.273Z
(BadInputsUTxO .... SafeHash "f3adbc5cd55a7473bfd12e944982f372282b12ba4611cf1293891b77f2b7a43a"}) (TxIx 1)]))
ash
CC BY-SA 4.0
2023-03-15T21:37:33.957Z
Ah, one problem is the build cmd is failing so it won't produce txbody output. This means the sign and submit cmds are using some older txbody. The `unConstrData` failure means script data cannot be deserialised, that's either the datum, redeemer or script context. I think it's your inline datum. Your validator expects `()` so you want to store `ScriptDataConstructor 0 []` at the script output not `ScriptDataMap [(ScriptDataBytes "constructor",ScriptDataNumber 0),(ScriptDataBytes "fields",ScriptDataList [])]`
james
CC BY-SA 4.0
2023-03-16T20:10:40.787Z
Thank you very much for your Help :D Tomorrow I will take another look into this problem, I will let you know how it goes.
ash
CC BY-SA 4.0
2023-03-14T14:33:44.473Z
2023-03-14T14:33:44.473Z
james
<p>I'm a have problem unlocking the smart contracts of the homework of week 02.</p>
<p>The Plutus code:</p>
<pre><code>{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE NoImplicitPrelude   #-}
{-# LANGUAGE TemplateHaskell     #-}

module Homework1 where

import qualified Plutus.V2.Ledger.Api as PlutusV2
import           PlutusTx             (compile)
import qualified PlutusTx.Prelude     (Bool, (&amp;&amp;),BuiltinData, True)
import           Utilities            (wrap, writeValidatorToFile, writeDataToFile)
import           Prelude              (IO)

---------------------------------------------------------------------------------------------------
----------------------------------- ON-CHAIN / VALIDATOR ------------------------------------------

{-# INLINABLE mkValidator #-}
-- This should validate if and only if the two Booleans in the redeemer are True!
mkValidator :: () -&gt; (PlutusTx.Prelude.Bool, PlutusTx.Prelude.Bool) -&gt; PlutusV2.ScriptContext -&gt; PlutusTx.Prelude.Bool
mkValidator _ (x,y) _ = (x &amp;&amp; y) 

wrappedVal :: PlutusTx.Prelude.BuiltinData -&gt; PlutusTx.Prelude.BuiltinData -&gt; PlutusTx.Prelude.BuiltinData -&gt; ()
wrappedVal = wrap mkValidator

validator :: PlutusV2.Validator
validator = PlutusV2.mkValidatorScript $$(PlutusTx.compile [|| wrappedVal ||])

saveHM :: IO ()
saveHM = writeValidatorToFile &quot;./Homework1.plutus&quot; validator
</code></pre>
<p>The cardano-cli script:</p>
<pre><code>cardano-cli transaction build \
    --babbage-era \
    --testnet-magic 2 \
    --tx-in &quot;$txin&quot; \
    --tx-in-script-file &quot;$assets/Homework1.plutus&quot; \
    --tx-in-inline-datum-present \
    --tx-in-redeemer-file &quot;$assets/redeemer-success.json&quot; \
    --tx-in-collateral &quot;$collateral&quot; \
    --change-address &quot;$(cat &quot;$keypath/$name.addr&quot;)&quot; \
    --protocol-params-file &quot;$pp&quot; \
    --out-file &quot;$body&quot; 
    
# Sign the transaction
cardano-cli transaction sign \
    --tx-body-file &quot;$body&quot; \
    --signing-key-file &quot;$keypath/$name.skey&quot; \
    --testnet-magic 2 \
    --out-file &quot;$tx&quot;

# Submit the transaction
cardano-cli transaction submit \
    --testnet-magic 2 \
    --tx-file &quot;$tx&quot;
</code></pre>
<p>And the redeemer that I generated using the <strong>writeDataToFile</strong> function of the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/fourth-iteration/code/Utilities/src/Utilities/Serialise.hs" rel="nofollow noreferrer">utilities module</a>. Both values are the serialization of the tuple (True,True)so the smart contract should be unlocking the funds:</p>
<pre><code>{&quot;constructor&quot;:0,&quot;fields&quot;:[{&quot;constructor&quot;:1,&quot;fields&quot;:[]},{&quot;constructor&quot;:1,&quot;fields&quot;:[]}]}
</code></pre>
<p>The above raises me this problem when building the transanction:</p>
<pre><code>Command failed: transaction build  Error: The following scripts have execution 
failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred:  User error:
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [
  (builtin unConstrData)
  (con data #a24b636f6e7374727563746f7200466669656c647380)
]
Script debugging logs:

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue 0 (fromList [])) (MaryValue 4799493069 (fromList []))))),UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn (TxId {_unTxId = SafeHash &quot;18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225&quot;}) (TxIx 1)]))))])
</code></pre>
<p>Thank you for your responses in forehand!</p>

CC BY-SA 4.0
2023-03-14T13:09:59.440Z
How is $txin defined? The error you're getting seems to be that there is a problem with the utxo in.
PREEB
CC BY-SA 4.0
2023-03-14T14:56:54.713Z
The txin is the utxo of the smart contract at id 0: e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad
you can see it here:
https://preview.cardanoscan.io/address/70919d457eac2f4e68d6835f8643852b51f7eecc7a2a9cd31d0944b24b
ash
CC BY-SA 4.0
2024-05-14T10:42:39.223Z
i was facing similar issue. just wanted to know if this one got fixed?
the error i get is: ```The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: (unConstrData (B #1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d)) : []
```
but the UTxO `1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d` is my wallet UTxO and is present in selections and collateral. any idea?
Reeshav Acharya
<plutus-pioneer-program>
The Plutus script evaluation failed [Homework Week 02]
# The Plutus script evaluation failed [Homework Week 02]

(Asked by: username_0 on 2023-03-14)

I'm a have problem unlocking the smart contracts of the homework of week 02.
The Plutus code:
{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE NoImplicitPrelude   #-}
{-# LANGUAGE TemplateHaskell     #-}

module Homework1 where

import qualified Plutus.V2.Ledger.Api as PlutusV2
import           PlutusTx             (compile)
import qualified PlutusTx.Prelude     (Bool, (&&),BuiltinData, True)
import           Utilities            (wrap, writeValidatorToFile, writeDataToFile)
import           Prelude              (IO)

---------------------------------------------------------------------------------------------------
----------------------------------- ON-CHAIN / VALIDATOR ------------------------------------------

{-# INLINABLE mkValidator #-}
-- This should validate if and only if the two Booleans in the redeemer are True!
mkValidator :: () -> (PlutusTx.Prelude.Bool, PlutusTx.Prelude.Bool) -> PlutusV2.ScriptContext -> PlutusTx.Prelude.Bool
mkValidator _ (x,y) _ = (x && y) 

wrappedVal :: PlutusTx.Prelude.BuiltinData -> PlutusTx.Prelude.BuiltinData -> PlutusTx.Prelude.BuiltinData -> ()
wrappedVal = wrap mkValidator

validator :: PlutusV2.Validator
validator = PlutusV2.mkValidatorScript $$(PlutusTx.compile [|| wrappedVal ||])

saveHM :: IO ()
saveHM = writeValidatorToFile "./Homework1.plutus" validator

The cardano-cli script:
cardano-cli transaction build \
    --babbage-era \
    --testnet-magic 2 \
    --tx-in "$txin" \
    --tx-in-script-file "$assets/Homework1.plutus" \
    --tx-in-inline-datum-present \
    --tx-in-redeemer-file "$assets/redeemer-success.json" \
    --tx-in-collateral "$collateral" \
    --change-address "$(cat "$keypath/$name.addr")" \
    --protocol-params-file "$pp" \
    --out-file "$body" 
    
# Sign the transaction
cardano-cli transaction sign \
    --tx-body-file "$body" \
    --signing-key-file "$keypath/$name.skey" \
    --testnet-magic 2 \
    --out-file "$tx"

# Submit the transaction
cardano-cli transaction submit \
    --testnet-magic 2 \
    --tx-file "$tx"

And the redeemer that I generated using the writeDataToFile function of the utilities module. Both values are the serialization of the tuple (True,True)so the smart contract should be unlocking the funds:
{"constructor":0,"fields":[{"constructor":1,"fields":[]},{"constructor":1,"fields":[]}]}

The above raises me this problem when building the transanction:
Command failed: transaction build  Error: The following scripts have execution 
failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred:  User error:
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [
  (builtin unConstrData)
  (con data #a24b636f6e7374727563746f7200466669656c647380)
]
Script debugging logs:

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue 0 (fromList [])) (MaryValue 4799493069 (fromList []))))),UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn (TxId {_unTxId = SafeHash "18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225"}) (TxIx 1)]))))])

Thank you for your responses in forehand!

**Tags:** plutus-pioneer-program
> **Comments:**
> **username_1**: How is $txin defined? The error you're getting seems to be that there is a problem with the utxo in.  
> **username_0**: The txin is the utxo of the smart contract at id 0: e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad you can see it here: https://preview.cardanoscan.io/address/70919d457eac2f4e68d6835f8643852b51f7eecc7a2a9cd31d0944b24b  
> **username_2**: i was facing similar issue. just wanted to know if this one got fixed? the error i get is: ```The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. Caused by: (unConstrData (B #1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d)) : [] ``` but the UTxO `1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d` is my wallet UTxO and is present in selections and collateral. any idea?  

---

## 1 answers

### Answer by username_3 on 2023-03-14. Score: 1

`BadInputsUTxO` means the input UTxO doesn't exist. It may have existed previosuly and has since been spent. Query the ledger state for current UTxOs and make sure to update your `$txin` accordingly.

> **Comments:**
> **username_0**: I'm confuse because the $txin is of the smart contract and is this:   e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad#0  You can view it here:   https://preview.cardanoscan.io/address/70919d457eac2f4e68d6835f8643852b51f7eecc7a2a9cd31d0944b24b  So the tx does indeed exist i think or could be expent (?)  
> **username_3**: It's complaining about `18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225#1` that I can confirm is not in the ledge state. Whats's `$collateral`?  
> **username_0**: Yes it is complaining about that utxo but the input was set with an id #0. I did the bash script again with another inputs this time, and results in an error with either of the $txin locked in the contract: a2a5f6a632d62bac847631b90749b11f43a2d861f8cd9c6bb3e7a4e0b7c64ca9#0 f3adbc5cd55a7473bfd12e944982f372282b12ba4611cf1293891b77f2b7a43a#0 and the collateral is: a5ff5ca6ef0525dd1eb337f8a385dfbd4715288f5bc47a76e44ad28eba9caffd#0 And then is ix complaining about with the last utxo at index #1, and that utxo doesn't exist at #1 just at #0 :S (whatever of both txin I use as an input $txin):  
> **username_0**: (BadInputsUTxO .... SafeHash "f3adbc5cd55a7473bfd12e944982f372282b12ba4611cf1293891b77f2b7a43a"}) (TxIx 1)]))  
> **username_3**: Ah, one problem is the build cmd is failing so it won't produce txbody output. This means the sign and submit cmds are using some older txbody. The `unConstrData` failure means script data cannot be deserialised, that's either the datum, redeemer or script context. I think it's your inline datum. Your validator expects `()` so you want to store `ScriptDataConstructor 0 []` at the script output not `ScriptDataMap [(ScriptDataBytes "constructor",ScriptDataNumber 0),(ScriptDataBytes "fields",ScriptDataList [])]`  
> **username_0**: Thank you very much for your Help :D Tomorrow I will take another look into this problem, I will let you know how it goes.  

---

