My validator script expects PubKeyHash and Currency symbol parameters in Datum. I wrote a script that compiles validator script to plutus and also forms Datum JSON parameters, as well as Redeemer parameters.

In validator script:

data Datum = Datum
    { owner  :: PubKeyHash
    , symbol :: CurrencySymbol

data Redeemer = ActionOne | ActionTwo

Compilation script uses this same Datum object structure imported from Validator, as well as Actions from Redeemer (note that I pass these values as parameters to this script and correctly form Datum object):

writePlutusScript :: Datum -> Redeemer -> Redeemer -> FilePath -> PlutusScript PlutusScriptV1 -> SBS.ShortByteString -> IO ()
writePlutusScript datum rOne rTwo filename scriptSerial scriptSBS =
  case Plutus.defaultCostModelParams of
        Just m ->
            pData = Plutus.toData datum
            (logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose m scriptSBS
                              [ pData
                              , Plutus.toData ()
                              , Plutus.toData dummyContext ]
          in do print ("Log output" :: String) >> print logout
                case e of
                  Left evalErr -> print ("Eval Error" :: String) >> print evalErr
                  Right exbudget -> print ("Ex Budget" :: String) >> print exbudget
                let datumData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData pData)
                print $ "Datum value: " <> datumData
                let rOneData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData rOne))
                print $ "One redeemer value: " <> rOneData
                rTwoData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData rTwo))
                print $ "Two redeemer value: " <> rTwoData

The output is like this for Datum:


And this for Redeemer:


But then I am trying to get Datum hash with Cardano-cli, using the very same JSON:

cardano-cli transaction hash-script-data --script-data-value INSERT_JSON_HERE

it fails with error:

Value out of range within the script data: INSERT_JSON_HERE
Byte strings in script data must consist of at most 64 bytes, but it consists of 112 bytes.

Then changing 'bytes' values to corresponding 'string' values, this datum hash command worked.

When I am trying to build the transaction using these values (providing --tx-in-datum-value SAME_DATUM_JSON_VALUE, --tx-in-redeemer-value SAME_REDEEMER_JSON_VALUE) with cardano-cli transaction build, it fails with:

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 provided Plutus code called 'error'.

The command I use:

cardano-cli transaction build --alonzo-era ${MAGIC} --tx-in SOMETHING --tx-in-script-file SOMETHING --tx-in-datum-value SOMETHING --tx-in-redeemer-value SOMETHING --tx-in-collateral SOMETHING --change-address SOMETHING --protocol-params-file pparams.json --out-file SOMETHING

THE QUESTION: Any ideas why is it failing to build, and maybe how to get clearer error message?

1 Answer 1


Check out my question I have made with similar problem.

My guess would be, you need to index redeemer as 0, instead of 1 and most important of all Datum bytes fields are too big. They take up 114 bytes of space while the most you can provide is 64!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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