1

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 =
  do
  case Plutus.defaultCostModelParams of
        Just m ->
          let
            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:

{
"constructor":0,
"fields":[
{"bytes":"6137356337356661467362633764353365663731356436343734356137613031633263316637363533623261653936323431336163353231"},
{"bytes":"6266636539643063643512345635636537356632356632323835346161373635396239633766323733633866643666623238393235623563"}
]
}

And this for Redeemer:

{"constructor":1,"fields":[]}

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

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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