<p>Check out <a href="https://cardano.stackexchange.com/questions/4661/how-does-custom-plutus-data-type-map-to-cardano-cli-tx-in-datum-file-content">my question</a> I have made with similar problem.</p>
<p>My guess would be, you need to index redeemer as 0, instead of 1 and most important of all <strong>Datum</strong> bytes fields are too big. They take up 114 bytes of space while the most you can provide is 64!</p>

CC BY-SA 4.0
2021-12-16T07:12:09.917Z
2021-12-16T07:12:09.917Z
KugisMugis
<p>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.</p>
<p>In validator script:</p>
<pre><code>data Datum = Datum
    { owner  :: PubKeyHash
    , symbol :: CurrencySymbol
    }

data Redeemer = ActionOne | ActionTwo
</code></pre>
<p>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):</p>
<pre><code>writePlutusScript :: Datum -&gt; Redeemer -&gt; Redeemer -&gt; FilePath -&gt; PlutusScript PlutusScriptV1 -&gt; SBS.ShortByteString -&gt; IO ()
writePlutusScript datum rOne rTwo filename scriptSerial scriptSBS =
  do
  case Plutus.defaultCostModelParams of
        Just m -&gt;
          let
            pData = Plutus.toData datum
            (logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose m scriptSBS
                              [ pData
                              , Plutus.toData ()
                              , Plutus.toData dummyContext ]
          in do print (&quot;Log output&quot; :: String) &gt;&gt; print logout
                case e of
                  Left evalErr -&gt; print (&quot;Eval Error&quot; :: String) &gt;&gt; print evalErr
                  Right exbudget -&gt; print (&quot;Ex Budget&quot; :: String) &gt;&gt; print exbudget
                let datumData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData pData)
                print $ &quot;Datum value: &quot; &lt;&gt; datumData
                let rOneData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData rOne))
                print $ &quot;One redeemer value: &quot; &lt;&gt; rOneData
                rTwoData = encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData rTwo))
                print $ &quot;Two redeemer value: &quot; &lt;&gt; rTwoData
</code></pre>
<p>The output is like this for Datum:</p>
<pre><code>{
&quot;constructor&quot;:0,
&quot;fields&quot;:[
{&quot;bytes&quot;:&quot;6137356337356661467362633764353365663731356436343734356137613031633263316637363533623261653936323431336163353231&quot;},
{&quot;bytes&quot;:&quot;6266636539643063643512345635636537356632356632323835346161373635396239633766323733633866643666623238393235623563&quot;}
]
}
</code></pre>
<p>And this for Redeemer:</p>
<pre><code>{&quot;constructor&quot;:1,&quot;fields&quot;:[]}
</code></pre>
<p>But then I am trying to get Datum hash with Cardano-cli, using the very same JSON:</p>
<pre><code>cardano-cli transaction hash-script-data --script-data-value INSERT_JSON_HERE
</code></pre>
<p>it fails with error:</p>
<pre><code>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.
</code></pre>
<p>Then changing 'bytes' values to corresponding 'string' values, this datum hash command worked.</p>
<p>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:</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 provided Plutus code called 'error'.
</code></pre>
<p>The command I use:</p>
<pre><code>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
</code></pre>
<p>THE QUESTION: Any ideas why is it failing to build, and maybe how to get clearer error message?</p>

<plutus><cardano-cli>
How to correctly build transaction using PubKeyHash or CurrencySymbol as Datum parameter in cardano-cli?
# How to correctly build transaction using PubKeyHash or CurrencySymbol as Datum parameter in cardano-cli?

(Asked by: username_0 on 2021-12-10)

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?

**Tags:** plutus, cardano-cli


---

## 1 answers

### Answer by username_1 on 2021-12-16. Score: 1

Check out [my question](https://cardano.stackexchange.com/questions/4661/how-does-custom-plutus-data-type-map-to-cardano-cli-tx-in-datum-file-content) 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!


---

