Skip to main content
Title
Link
gRebel
  • 1.8k
  • 1
  • 9
  • 36

Usage of Plutus function TxSIgnedBy - transaction build Error: The Plutus script evaluation failed

Source Link

Usage of Plutus function TxSIgnedBy

I'm trying to use Plutus function txSignedBy with a transaction involving the usage of cardano-cli

I first sent some UtxO to my script address, with a datum whose structure is like this:

data TradeDetail = TradeDetail
    { tradeOwner        :: !PubKeyHash
    } deriving (Generic, ToJSON, FromJSON)

data TradeDatum = TradeDatum TradeDetail
    deriving (Generic, ToJSON, FromJSON)

To build the datum,

  1. I first generated the public key hash from my verificaiton key like this:

    cardano-cli address key-hash --payment-verification-key-file mykey.vkey and got 59b07e6d2500c82f6325ac18d7624cfbdb83a92e061c31068e6b03f9

  2. Then I created the Datum JSON file encapsulating the public key hash

{
   "fields":[
      {
         "fields":[
            {
               "bytes":"59b07e6d2500c82f6325ac18d7624cfbdb83a92e061c31068e6b03f9"
            }
         ],
         "constructor":0
      }
   ],
   "constructor":0
}

My problem happens when I try to retrieve the UtxO from the script, providing the datum. The validator sub-function where the error happens, in the ON-chain code, is like this:

{-# INLINABLE getback #-}
getback :: ContractInfo -> TradeDetail -> ScriptContext -> Bool
getback ci details context =

    traceIfFalse message $ 
        (scriptContextTxInfo context) `txSignedBy` (tradeOwner details)
    
    where

        message :: BuiltinString
        message = "Tx has to be signed by the item owner " `appendString` decodeUtf8 (getPubKeyHash (tradeOwner details))

When using cardano-cli to get back the UtxO, signing with mykey.skey, I get the error:

Command failed: transaction build  Error: The following scripts have execution failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred:  User error:
The provided Plutus code called 'error'.
Caused by: [
  (builtin decodeUtf8)
  (con bytestring #59b07e6d2500c82f6325ac18d7624cfbdb83a92e061c31068e6b03f9)
]

I don't know why my error message is not well formatted, but at least the public key hash is correctly displayed. This shows that, at the minimum, the datum is unpacked correctly and the public key hash is extracted.

But the question is, why function txSignedBy returns false ?