Given the following smart contract:
{-# INLINEABLE mkValidator #-}
mkValidator :: PubKeyHash -> BuiltinData -> ScriptContext -> Bool
mkValidator beneficiary _ ctx =
traceIfFalse "tx not signed by beneficiary" signedByBeneficiary
where
info :: Ledger.TxInfo
info = scriptContextTxInfo ctx
signedByBeneficiary :: Bool
signedByBeneficiary = txSignedBy info beneficiary
It only allows consumption of its' UTxO if the transaction is signed by a key that's part of the UTxO's datum.
I've sent some funds to the script address and verified the datum is correct.
Now I'm trying to create a transaction that consumes a UTxO from the script address with the cardano-cli transaction build
command. However, the command runs the script validator locally before I've had a chance to sign the transaction. Therefore, the command fails with error PT5: tx not signed by beneficiary
. This is expected because during that validation, the signature is not available in the ScriptContext
.
How can I, either disable the local validator check, or attach a signature to the ScriptContext
so the validator succeeds? I've tried the --required-signer
option on the cardano-cli transaction build
command but to no luck.
The failing command:
cardano-cli transaction build \
--alonzo-era \
--testnet-magic 1097911063 \
--tx-in 213b67f21034e4f4684b871da9a8c7a1ed867ff2eef02232c064e2004b7dc316#1 \
--tx-in-script-file Owner.plutus \
--tx-in-datum-value "\"$(cardano-cli address key-hash --payment-verification-key-file payment.vkey)\"" \
--tx-in-redeemer-value 0 \
--tx-in-collateral 213b67f21034e4f4684b871da9a8c7a1ed867ff2eef02232c064e2004b7dc316#0 \
--change-address $(cat payment.addr) \
--protocol-params-file pparams.json \
--out-file tx.build
--required-signer
part of the command? It should be able to solve the problem you have.payment.vkey
andpayment.skey
. While the verification key (vkey) was used to create the datum value, I used the signing key (skey) for the required signer:--required-signer payment.skey
. Since the ordering matters, I used the option right after the--tx-in-redeemer-value
option.