user140: 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


user705: I am afraid that via the cardano-cli, you will not be able to do that. Indeed the cli evaluates the execution units before you get to sign the transaction.
Signatories are however available in the script context from a Plutus standpoint. Right now, I don't know any other way than doing it "the Haskell way" and by pre-constructing the transaction via the very same Haskell libraries used by the cardano-ledger. This will allow you to construct the script context necessary for your script to validate. A way to approach this is typically by running your script considering an unlimited budget, and then, replace this "unlimited budget" with the actual cost of execution that your observed -- hoping that this won't change the cost.
Incidentally, calculating script execution for a transaction is a kind of chicken-and-egg situation. For example, you need to know the execution cost of your script in order to balance your transaction for fees, but adjusting outputs for fees may also change the execution cost of your script. To avoid this, the cardano-cli was designed in a way that makes this process easy and deterministic. Yet, it comes with some drawbacks for scripts like yours which require some extra context.
Another option is to raise this as an issue to the team working on the cardano-cli (Github issues) to let them know of the design issue.

140: <p>Given the following smart contract:</p>
<pre><code>{-# INLINEABLE mkValidator #-}
mkValidator :: PubKeyHash -&gt; BuiltinData -&gt; ScriptContext -&gt; Bool
mkValidator beneficiary _ ctx =
  traceIfFalse &quot;tx not signed by beneficiary&quot; signedByBeneficiary
  where
    info :: Ledger.TxInfo
    info = scriptContextTxInfo ctx

    signedByBeneficiary :: Bool
    signedByBeneficiary = txSignedBy info beneficiary
</code></pre>
<p>It only allows consumption of its' UTxO if the transaction is signed by a key that's part of the UTxO's datum.</p>
<p>I've sent some funds to the script address and verified the datum is correct.</p>
<p>Now I'm trying to create a transaction that consumes a UTxO from the script address with the <code>cardano-cli transaction build</code> command. However, the command runs the script validator locally before I've had a chance to sign the transaction. Therefore, the command fails with <code>error PT5: tx not signed by beneficiary</code>. This is expected because during that validation, the signature is not available in the <code>ScriptContext</code>.</p>
<p>How can I, either disable the local validator check, or attach a signature to the <code>ScriptContext</code> so the validator succeeds? I've tried the <code>--required-signer</code> option on the <code>cardano-cli transaction build</code> command but to no luck.</p>
<hr />
<p>The failing command:</p>
<pre><code>cardano-cli transaction build \
--alonzo-era \
--testnet-magic 1097911063 \
--tx-in 213b67f21034e4f4684b871da9a8c7a1ed867ff2eef02232c064e2004b7dc316#1 \
--tx-in-script-file Owner.plutus \
--tx-in-datum-value &quot;\&quot;$(cardano-cli address key-hash --payment-verification-key-file payment.vkey)\&quot;&quot; \
--tx-in-redeemer-value 0 \
--tx-in-collateral 213b67f21034e4f4684b871da9a8c7a1ed867ff2eef02232c064e2004b7dc316#0 \
--change-address $(cat payment.addr) \
--protocol-params-file pparams.json \
--out-file tx.build
</code></pre>
 705: <p>I am afraid that via the cardano-cli, you will not be able to do that. Indeed the cli evaluates the execution units before you get to sign the transaction.</p>
<p>Signatories are however available in the script context from a Plutus standpoint. Right now, I don't know any other way than doing it &quot;the Haskell way&quot; and by pre-constructing the transaction via the very same Haskell libraries used by the cardano-ledger. This will allow you to construct the script context necessary for your script to validate. A way to approach this is typically by running your script considering an unlimited budget, and then, replace this &quot;unlimited budget&quot; with the actual cost of execution that your observed -- hoping that this won't change the cost.</p>
<p>Incidentally, calculating script execution for a transaction is a kind of chicken-and-egg situation. For example, you need to know the execution cost of your script in order to balance your transaction for fees, but adjusting outputs for fees may also change the execution cost of your script. To avoid this, the cardano-cli was designed in a way that makes this process easy and deterministic. Yet, it comes with some drawbacks for scripts like yours which require some extra context.</p>
<p>Another option is to raise this as an issue to the team working on the cardano-cli (Github issues) to let them know of the design issue.</p>
