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:


The above raises me this problem when building the transanction:

Command failed: transaction build  Error: The following scripts have execution 
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!

  • 1
    How is $txin defined? The error you're getting seems to be that there is a problem with the utxo in.
    – PREEB
    Commented Mar 14, 2023 at 13:09
  • The txin is the utxo of the smart contract at id 0: e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad you can see it here: preview.cardanoscan.io/address/…
    – ash
    Commented Mar 14, 2023 at 14:56
  • 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? Commented May 14 at 10:42

1 Answer 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.

  • I'm confuse because the $txin is of the smart contract and is this: e6bfde96d8c6e1c0fafca91bebca1d0bc35034183ed1a824753835e2630c26ad#0 You can view it here: preview.cardanoscan.io/address/… So the tx does indeed exist i think or could be expent (?)
    – ash
    Commented Mar 14, 2023 at 15:00
  • 1
    It's complaining about 18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225#1 that I can confirm is not in the ledge state. Whats's $collateral?
    – james
    Commented Mar 15, 2023 at 10:19
  • 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
    Commented Mar 15, 2023 at 16:35
  • (BadInputsUTxO .... SafeHash "f3adbc5cd55a7473bfd12e944982f372282b12ba4611cf1293891b77f2b7a43a"}) (TxIx 1)]))
    – ash
    Commented Mar 15, 2023 at 16:35
  • 1
    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
    Commented Mar 15, 2023 at 21:37

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.