0

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?

1
  • I dig more into this and now I think it doesn't work because PlutusTx.unstableMakeIsDatafails to generate required instances for FromData
    – KugisMugis
    Apr 11, 2022 at 7:10

2 Answers 2

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
{...}
2
  • 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
    Apr 11, 2022 at 9:21
  • @KugisMugis In that case, can you post complete on chain and off chain code?
    – lambda
    Apr 11, 2022 at 9:44
0

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)

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.