1

This is the code of my smart contract. It basically requires exactly 3 reference inputs to pass validation.

{-# LANGUAGE NoImplicitPrelude  #-} 
{-# LANGUAGE TemplateHaskell    #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

module RefInputV3 where

import PlutusTx.Prelude
import PlutusTx 
import PlutusLedgerApi.V3

{-# INLINABLE mkValidator #-}
mkValidator :: ()  -> () -> ScriptContext  -> Bool
mkValidator dat_ redm_ ctx  = let 
    info = scriptContextTxInfo ctx
    refInputs = txInfoReferenceInputs info 
    in (traceIfFalse "Requires 3 Reference Inputs" (length refInputs == 3))

{-# INLINABLE mkWrappedValidator #-}
mkWrappedValidator ::  BuiltinData -> BuiltinData -> BuiltinData -> ()
mkWrappedValidator d r c = check $ mkValidator (unsafeFromBuiltinData d) (unsafeFromBuiltinData r) (unsafeFromBuiltinData c)

validator :: CompiledCode (BuiltinData -> BuiltinData -> BuiltinData -> ())
validator =  $$(PlutusTx.compile [|| mkWrappedValidator ||]) 

i am generating the script in the following way:

genV3Script :: PlutusScript PlutusScriptV3
genV3Script = PlutusScriptSerialised $ serialiseCompiledCode validator

main :: IO ()
main = do 
    void $ writeFileTextEnvelope "deploy/refInputV3.plutus" Nothing genV3Script

now the cardano-cli transaction to redeem this with 3 reference inputs would be:

execSync(`cardano-cli conway transaction build \
--socket-path ${SOCKET_PATH} \
--testnet-magic 4 \
--tx-in 279d8c56780816945e717dbcf53d59c8b3f1e81766c0ea02d43ef8298d5ef4f6#0 \
--tx-in-collateral ${txin} \
--tx-in-script-file ../deploy/refInputV3.plutus \
--tx-in-inline-datum-present \
--tx-in-redeemer-file tx/redeemer.json \
--tx-out ${paymentAddress}+10000000 \
--read-only-tx-in-reference d18e8cb751a6f611c7d0eadf0f0b42c60877a8b13b1f3871ec7e9fe2f584dfa4#0 \
--read-only-tx-in-reference 1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d#2 \
--read-only-tx-in-reference 1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d#4 \
--change-address ${paymentAddress} \
--out-file tx/refInputV3.json`)

the error i am getting is:

The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [
  (builtin unConstrData)
  (con
    data (B #279d8c56780816945e717dbcf53d59c8b3f1e81766c0ea02d43ef8298d5ef4f6)
  )
]

can anyone help me with this?

0

Your Answer

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