0

I am trying to unlock an NFT that I locked into a script address. The unlocking succeds when I have some basic validation rules but when I add the minterIsPaid rule below, the validitation transaction fails.

data AssetPurchase = AssetPurchase {
    nft :: !TokenName
   ,minter :: !Address 
   ,minterCurrency :: !AssetClass
   ,minterAmount :: !Integer
   ,beneficiary :: !Address
   ,beneficiaryAmount :: !Integer
   ,beneficiaryCurrency :: !AssetClass
   ,collateral :: !AssetClass
   ,collateralAmnt :: !Integer
} deriving (Show, Generic, FromJSON, ToJSON)

purchaseValidator :: AssetPurchase -> () -> () -> ScriptContext -> Bool 
purchaseValidator p () () ctx  = validate 
    where
        validate ::  Bool
        validate =   validateTxOuts && minterIsPaid 

         minterIsPaid :: Bool
         minterIsPaid = assetClassValueOf (valuePaidToAddress (minter 
                        p)) (minterCurrency p) == minterAmount p

         valuePaidToAddress :: Address -> Value
         valuePaidToAddress addr = mconcat (fmap txOutValue (filter 
                     (\x -> txOutAddress x == addr) (txInfoOutputs 
                     (scriptContextTxInfo ctx))))
...

My parameters for deploying this contract look like this:

writeAssetPurchaseValidator = writeValidator "token/lock/mds-lock.plutus" $ validator $ AssetPurchase 
                                {
                                    nft= Ledger.Value.tokenName $ TE.encodeUtf8 $ T.pack "MediSnap#06"
                                   ,minter = L.pubKeyHashAddress (L.PaymentPubKeyHash $  L.PubKeyHash $ BuiltinByteString $  TE.encodeUtf8 $ T.pack "bebe8013168a1f3607bddb3a170b0adb12400316a8bcf34b7efedf0a") Nothing 
                                   ,minterCurrency = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack "") (Ledger.Value.tokenName  $ TE.encodeUtf8 $ T.pack "")
                                   ,minterAmount = 2000000
                                   ,beneficiary = L.pubKeyHashAddress (L.PaymentPubKeyHash $  L.PubKeyHash $ BuiltinByteString $  TE.encodeUtf8 $ T.pack "482421baa0219f801aa40f91dd8ec5d6ded4631a73f09b9d9b29848c") Nothing
                                   ,beneficiaryCurrency = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack "") (Ledger.Value.tokenName  $ TE.encodeUtf8 $ T.pack "")
                                   ,beneficiaryAmount = 2000000
                                   ,collateral = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack "") (Ledger.Value.tokenName $ TE.encodeUtf8 $ T.pack "")
                                   ,collateralAmnt = 2000000
                                }

My unlocking transaction is as shown:

cardano-cli transaction build-raw \
     --babbage-era \
    --tx-in 05be931d5f807650412724cb75faa7da3c898ccbeddd5b762dc8480b12ca6875#0 \
    --tx-in-datum-file "../token/lock/unit.json" \
    --tx-in-redeemer-file "../token/lock/unit.json" \
    --tx-in-script-file "../token/lock/mds-lock.plutus" \
    --tx-out $(cat ../wallets/buyer/buyer.addr)+"2130271 lovelace + 1 6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2.4d656469536e61702336" \
    --tx-out $(cat ../wallets/beneficiary/beneficiary.addr)+2000000 \
    --tx-out $(cat ../wallets/minter/minter.addr)+2000000 \
    --tx-in-collateral "dc6fba11e10917236072a200c5e9e8b2c5c95d317d9b924bd736952fb5153c39#0" \
    --tx-in-execution-units="(10000000000, 14000000)" \
    --protocol-params-file "../token/lock/protocol-params.json" \
    --fee 1869729  \
    --out-file "../token/unlock/tx.body"

cardano-cli transaction sign \
    --tx-body-file "../token/unlock/tx.body" \
    --signing-key-file "../wallets/buyer/buyer.skey" \
    --$TS \
    --out-file "../token/unlock/tx.signed"

When I run this unlock transaction, I get an error which is not very helpful. The error is:\n CekError An error has occurred: User error:\nThe machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (UtxosFailure (ValidationTagMismatch (IsValid True) (FailedUnexpectedly (PlutusFailure "\nThe 3 arg plutus script (PlutusScript PlutusV1 ScriptHash \"a83254bf933b34d7d0072c3270a07cf1d9c87d34b01ffdf8ae29d959\") fails.\nCekError An error has occurred:  User error:\nThe machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\nThe protocol version is: ProtVer {pvMajor = 7, pvMinor = 0}\nThe data is: Constr 0 []\nThe redeemer is: Constr 0 []\nThe context is:\nPurpose: Spending (TxOutRef {txOutRefId = 05be931d5f807650412724cb75faa7da3c898ccbeddd5b762dc8480b12ca6875, txOutRefIdx = 0})\nTxInfo:\n  TxId: c5c5a5a47c7f3f204aafe3b2a2cea20ceb2fab7f1a0a3d162508ad0fe601b77d\n  Inputs: [ 05be931d5f807650412724cb75faa7da3c898ccbeddd5b762dc8480b12ca6875!0 -> - Value (Map [(,Map [(\"\",8000000)]),(6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2,Map [(\"MediSnap#6\",1)])]) addressed to\n                                                                                    ScriptCredential: a83254bf933b34d7d0072c3270a07cf1d9c87d34b01ffdf8ae29d959 (no staking credential) ]\n  Outputs: [ - Value (Map [(,Map [(\"\",2130271)]),(6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2,Map [(\"MediSnap#6\",1)])]) addressed to\n               PubKeyCredential: 08498419e83871d01aae9c97a45218f3aedc0b963f787569ce0c1463 (no staking credential)\n           , - Value (Map [(,Map [(\"\",2000000)])]) addressed to\n               PubKeyCredential: 482421baa0219f801aa40f91dd8ec5d6ded4631a73f09b9d9b29848c (no staking credential)\n           , - Value (Map [(,Map [(\"\",2000000)])]) addressed to\n               PubKeyCredential: bebe8013168a1f3607bddb3a170b0adb12400316a8bcf34b7efedf0a (no staking credential) ]\n  Fee: Value (Map [(,Map [(\"\",1869729)])])\n  Value minted: Value (Map [])\n  DCerts: []\n  Wdrl: []\n  Valid range: (-\8734 , +\8734)\n  Signatories: []\n  Datums: [ ( 923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec\n          , <> ) ]\n"
... 
alot of text for datum hashes 

Any ideas what could be goin wrong?

2
  • I've seen this message before [...] because of an error, either from a built-in function or from an explicit use of 'error' [...] when I tried running a Plutus v1 script with Plutus v2 context. Perhaps check if you're using any v1/v2 builtins unintentionally depending on your version choice.
    – Will
    Commented Oct 11, 2022 at 15:03
  • Yep, checked all my imports, looks ok. All versioned imports have V1
    – Skelli
    Commented Oct 12, 2022 at 13:58

1 Answer 1

2

First, try adding trace logs to your validator, i.e. use traceIfFalse with a unique message for each condition.

Then using cli's build cmd instead of build-raw. It runs script evaluation and prints trace log output on failure.

1
  • Nice. Adding the traceIfFalse and using build helped alot. From the error logs, I got code PT5) and using (plutus.readthedocs.io/en/latest/…) ,I am thinking that the minterIsPaid function retuns a false. Now if only I can tell why..thanks!
    – Skelli
    Commented Oct 12, 2022 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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