<p>Problem was I didn't provide correct type to <code>submitTxConstraintsWith</code> call.</p>
<p>If this was code from Plutus Pioneer Program week one where there is a definition:</p>
<pre><code>data Auctioning
instance Scripts.ValidatorTypes Auctioning where
    type instance RedeemerType Auctioning = AuctionAction
    type instance DatumType Auctioning = AuctionDatum
</code></pre>
<p>Call should look like this:</p>
<pre><code>ledgerTx &lt;- submitTxConstraintsWith @Auctioning lookups constraints
</code></pre>
<p>Also datum needs <code>deriving (Show, Generic, ToJSON, FromJSON)</code> for serialization</p>
<pre><code>data RandomDatum = RandomDatum {
   { tn :: !TokenName
   , cs :: !CurrencySymbol
   , nn :: !Integer
   } deriving (Show, Generic, ToJSON, FromJSON)
</code></pre>

CC BY-SA 4.0
2022-04-11T10:07:22.053Z
2022-04-13T15:14:03.383Z
2022-04-13T15:14:03.383Z
KugisMugis
<p>As far as I know your datum types are required to conform the Data type.
Try:</p>
<pre><code>PlutusTx.makeIsDataIndexed ''RandomDatum [ ('RandomDatum, 0) ]

{...}
let randomDatum = RandomDatum { ...params... }
    tx          = mustPayToTheScript randomDatum $ Ada.lovelaceValueOf amount
{...}
</code></pre>

CC BY-SA 4.0
2022-04-11T09:21:19.933Z
Maybe I'm missing some Haskell Language pragma which is required for this? What pragrams are required for this? I do have `PlutusTx.makeIsDataIndexed` in separate `on-chain` code file but I still get this error.
KugisMugis
CC BY-SA 4.0
2022-04-11T09:44:34.210Z
@KugisMugis In that case, can you post complete on chain and off chain code?
lambda
CC BY-SA 4.0
2022-04-11T07:33:37.510Z
2022-04-12T08:14:08.247Z
2022-04-12T08:14:08.247Z
Will
<p>Lets say I on-chain i have a Datum like so:</p>
<pre><code>data RandomDatum = RandomDatum {
   { tn :: !TokenName
   , cs :: !CurrencySymbol
   , nn :: !Integer
   } deriving (Show)
</code></pre>
<p>Off chain I'm trying to form and submit transaction with:</p>
<pre><code>...
let dat = RandomDatum { 
       tn = &quot;&quot;
     , cs = &quot;&quot;
     , nn = 1
    }
    constraints = Constraints.mustPayToOtherScript vh dat val

ledgerTx &lt;- submitTxConstraintsWith lookups constraints
</code></pre>
<p>But my compilation always fails, because <code>dat</code> is not of type <code>Datum</code>.
I have also tried:</p>
<pre><code>constraints = Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData dat) val
</code></pre>
<h1>Question</h1>
<p>How could I convert <code>RandomDatum</code> imported from my <code>on-chain</code> code file?</p>

CC BY-SA 4.0
2022-04-11T07:10:04.937Z
I dig more into this and now I think it doesn't work because `PlutusTx.unstableMakeIsData`fails to generate required instances for `FromData`
KugisMugis
<plutus><datum><offchain><builtindata>
Using custom datum for `mustPayToOtherScript` in off-chain code
# Using custom datum for `mustPayToOtherScript` in off-chain code

(Asked by: username_0 on 2022-04-10)

Lets say I on-chain i have a Datum like so:
data RandomDatum = RandomDatum {
   { tn :: !TokenName
   , cs :: !CurrencySymbol
   , nn :: !Integer
   } deriving (Show)

Off chain I'm trying to form and submit transaction with:
...
let dat = RandomDatum { 
       tn = ""
     , cs = ""
     , nn = 1
    }
    constraints = Constraints.mustPayToOtherScript vh dat val

ledgerTx <- submitTxConstraintsWith lookups constraints

But my compilation always fails, because dat is not of type Datum.
I have also tried:
constraints = Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData dat) val

Question
How could I convert RandomDatum imported from my on-chain code file?

**Tags:** plutus, datum, offchain, builtindata
> **Comments:**
> **username_0**: I dig more into this and now I think it doesn't work because `PlutusTx.unstableMakeIsData`fails to generate required instances for `FromData`  

---

## 2 answers

### Answer by username_0 on 2022-04-11. Score: 0 | Accepted answer

Problem was I didn't provide correct type to submitTxConstraintsWith call.
If this was code from Plutus Pioneer Program week one where there is a definition:
data Auctioning
instance Scripts.ValidatorTypes Auctioning where
    type instance RedeemerType Auctioning = AuctionAction
    type instance DatumType Auctioning = AuctionDatum

Call should look like this:
ledgerTx <- submitTxConstraintsWith @Auctioning lookups constraints

Also datum needs deriving (Show, Generic, ToJSON, FromJSON) for serialization
data RandomDatum = RandomDatum {
   { tn :: !TokenName
   , cs :: !CurrencySymbol
   , nn :: !Integer
   } deriving (Show, Generic, ToJSON, FromJSON)


---

### Answer by username_1 on 2022-04-11. Score: 1

As far as I know your datum types are required to conform the Data type.
Try:
PlutusTx.makeIsDataIndexed ''RandomDatum [ ('RandomDatum, 0) ]

{...}
let randomDatum = RandomDatum { ...params... }
    tx          = mustPayToTheScript randomDatum $ Ada.lovelaceValueOf amount
{...}

> **Comments:**
> **username_0**: Maybe I'm missing some Haskell Language pragma which is required for this? What pragrams are required for this? I do have `PlutusTx.makeIsDataIndexed` in separate `on-chain` code file but I still get this error.  
> **username_2**: @KugisMugis In that case, can you post complete on chain and off chain code?  

---

