<p>First, try adding trace logs to your validator, i.e. use <code>traceIfFalse</code> with a unique message for each condition.</p>
<p>Then using cli's <code>build</code> cmd instead of <code>build-raw</code>. It runs script evaluation and prints trace log output on failure.</p>

CC BY-SA 4.0
2022-10-12T14:00:27.293Z
Nice. Adding the `traceIfFalse` and using `build` helped alot. From the error logs,  I got code PT5) and using (https://plutus.readthedocs.io/en/latest/troubleshooting.html#error-codes) ,I am thinking that the `minterIsPaid` function retuns a false. Now if only I can tell why..thanks!
Skelli
CC BY-SA 4.0
2022-10-11T15:59:46.983Z
2022-10-11T15:59:46.983Z
james
<p>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 <code>minterIsPaid</code> rule below, the validitation transaction fails.</p>
<pre><code>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 -&gt; () -&gt; () -&gt; ScriptContext -&gt; Bool 
purchaseValidator p () () ctx  = validate 
    where
        validate ::  Bool
        validate =   validateTxOuts &amp;&amp; minterIsPaid 

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

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

</code></pre>
<p>My parameters for deploying this contract look like this:</p>
<pre><code>writeAssetPurchaseValidator = writeValidator &quot;token/lock/mds-lock.plutus&quot; $ validator $ AssetPurchase 
                                {
                                    nft= Ledger.Value.tokenName $ TE.encodeUtf8 $ T.pack &quot;MediSnap#06&quot;
                                   ,minter = L.pubKeyHashAddress (L.PaymentPubKeyHash $  L.PubKeyHash $ BuiltinByteString $  TE.encodeUtf8 $ T.pack &quot;bebe8013168a1f3607bddb3a170b0adb12400316a8bcf34b7efedf0a&quot;) Nothing 
                                   ,minterCurrency = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack &quot;&quot;) (Ledger.Value.tokenName  $ TE.encodeUtf8 $ T.pack &quot;&quot;)
                                   ,minterAmount = 2000000
                                   ,beneficiary = L.pubKeyHashAddress (L.PaymentPubKeyHash $  L.PubKeyHash $ BuiltinByteString $  TE.encodeUtf8 $ T.pack &quot;482421baa0219f801aa40f91dd8ec5d6ded4631a73f09b9d9b29848c&quot;) Nothing
                                   ,beneficiaryCurrency = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack &quot;&quot;) (Ledger.Value.tokenName  $ TE.encodeUtf8 $ T.pack &quot;&quot;)
                                   ,beneficiaryAmount = 2000000
                                   ,collateral = Ledger.Value.assetClass (Ledger.Value.currencySymbol $ TE.encodeUtf8 $ T.pack &quot;&quot;) (Ledger.Value.tokenName $ TE.encodeUtf8 $ T.pack &quot;&quot;)
                                   ,collateralAmnt = 2000000
                                }
</code></pre>
<p>My unlocking transaction is as shown:</p>
<pre><code>cardano-cli transaction build-raw \
     --babbage-era \
    --tx-in 05be931d5f807650412724cb75faa7da3c898ccbeddd5b762dc8480b12ca6875#0 \
    --tx-in-datum-file &quot;../token/lock/unit.json&quot; \
    --tx-in-redeemer-file &quot;../token/lock/unit.json&quot; \
    --tx-in-script-file &quot;../token/lock/mds-lock.plutus&quot; \
    --tx-out $(cat ../wallets/buyer/buyer.addr)+&quot;2130271 lovelace + 1 6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2.4d656469536e61702336&quot; \
    --tx-out $(cat ../wallets/beneficiary/beneficiary.addr)+2000000 \
    --tx-out $(cat ../wallets/minter/minter.addr)+2000000 \
    --tx-in-collateral &quot;dc6fba11e10917236072a200c5e9e8b2c5c95d317d9b924bd736952fb5153c39#0&quot; \
    --tx-in-execution-units=&quot;(10000000000, 14000000)&quot; \
    --protocol-params-file &quot;../token/lock/protocol-params.json&quot; \
    --fee 1869729  \
    --out-file &quot;../token/unlock/tx.body&quot;

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

</code></pre>
<p>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'.</p>
<pre><code>Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (UtxosFailure (ValidationTagMismatch (IsValid True) (FailedUnexpectedly (PlutusFailure &quot;\nThe 3 arg plutus script (PlutusScript PlutusV1 ScriptHash \&quot;a83254bf933b34d7d0072c3270a07cf1d9c87d34b01ffdf8ae29d959\&quot;) 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 -&gt; - Value (Map [(,Map [(\&quot;\&quot;,8000000)]),(6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2,Map [(\&quot;MediSnap#6\&quot;,1)])]) addressed to\n                                                                                    ScriptCredential: a83254bf933b34d7d0072c3270a07cf1d9c87d34b01ffdf8ae29d959 (no staking credential) ]\n  Outputs: [ - Value (Map [(,Map [(\&quot;\&quot;,2130271)]),(6669034a6d4719d62097b5ed28f81e76b80ca2a289d9a4aceabc38d2,Map [(\&quot;MediSnap#6\&quot;,1)])]) addressed to\n               PubKeyCredential: 08498419e83871d01aae9c97a45218f3aedc0b963f787569ce0c1463 (no staking credential)\n           , - Value (Map [(,Map [(\&quot;\&quot;,2000000)])]) addressed to\n               PubKeyCredential: 482421baa0219f801aa40f91dd8ec5d6ded4631a73f09b9d9b29848c (no staking credential)\n           , - Value (Map [(,Map [(\&quot;\&quot;,2000000)])]) addressed to\n               PubKeyCredential: bebe8013168a1f3607bddb3a170b0adb12400316a8bcf34b7efedf0a (no staking credential) ]\n  Fee: Value (Map [(,Map [(\&quot;\&quot;,1869729)])])\n  Value minted: Value (Map [])\n  DCerts: []\n  Wdrl: []\n  Valid range: (-\8734 , +\8734)\n  Signatories: []\n  Datums: [ ( 923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec\n          , &lt;&gt; ) ]\n&quot;
... 
alot of text for datum hashes 
</code></pre>
<p>Any ideas what could be goin wrong?</p>

CC BY-SA 4.0
2022-10-11T15:03:54.647Z
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
CC BY-SA 4.0
2022-10-12T13:58:06.790Z
Yep, checked all my imports, looks ok. All versioned imports have `V1`
Skelli
<plutus><transaction>
Failing Validation on Script Address
# Failing Validation on Script Address

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

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?

**Tags:** plutus, transaction
> **Comments:**
> **username_1**: 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.  
> **username_0**: Yep, checked all my imports, looks ok. All versioned imports have `V1`  

---

## 1 answers

### Answer by username_2 on 2022-10-11. Score: 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.

> **Comments:**
> **username_0**: Nice. Adding the `traceIfFalse` and using `build` helped alot. From the error logs,  I got code PT5) and using (https://plutus.readthedocs.io/en/latest/troubleshooting.html#error-codes) ,I am thinking that the `minterIsPaid` function retuns a false. Now if only I can tell why..thanks!  

---

