user4596: 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?

user5085: 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
{...}


4596: <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>
 5085: <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>
