<p>This was answered in PPP Q&amp;A, the issue was the string literals in Plutus Core code.
Instead, one has to use variables</p>
<pre><code>{-# INLINABLE mkPolicy #-}
mkPolicy :: PaymentPubKeyHash -&gt; () -&gt; ScriptContext -&gt; Bool
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ 
unPaymentPubKeyHash pkh
</code></pre>
<p>and put the literal into the liftCode expression:</p>
<pre><code>policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $
$$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
`PlutusTx.applyCode`
PlutusTx.liftCode (PaymentPubKeyHash &quot;a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2&quot;)
</code></pre>

CC BY-SA 4.0
2022-03-03T20:10:46.403Z
2022-03-03T20:10:46.403Z
DaveStrider
<p>When modifying the week5 code in e.g. Signed.hs from</p>
<pre><code>mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ unPaymentPubKeyHash pkh
</code></pre>
<p>to the hard-coded pkh from Wallet 1,</p>
<pre><code>mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ PubKeyHash &quot;a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2&quot;
</code></pre>
<p>the validation fails with</p>
<pre><code>CONTRACT STOPPED WITH ERROR: &quot;\&quot;WalletError (ValidationError (ScriptFailure (EvaluationError [\\\&quot;PT5\\\&quot;] \\\&quot;CekEvaluationFailure\\\&quot;)))\&quot;&quot;
</code></pre>
<p>I verified in the repl:</p>
<pre><code>mockWalletPaymentPubKeyHash (knownWallet 1)
a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2
</code></pre>
<p>and also in the offchain code logging Contract.ownPaymentPubKeyHash gives the same a2c2...09c2 hash.</p>
<p>What is going wrong here?</p>
<p>I unsuccessfully tried to debug it with</p>
<pre><code>mkPolicy pkh () ctx = traceError $ decodeUtf8 $ getPubKeyHash $ head $ txInfoSignatories (scriptContextTxInfo ctx)
</code></pre>
<p>which resulted in an error as well.</p>
<pre><code>CONTRACT STOPPED WITH ERROR: &quot;\&quot;WalletError (ValidationError (ScriptFailure (EvaluationError [] \\\&quot;BuiltinEvaluationFailure of DecodeUtf8\\\&quot;)))\&quot;&quot;
</code></pre>
<p>What is the correct way to debug this? e.g. in this case to check what the pkh used in the onchain code was? Is decodeUtf8 the right function at all for BuiltinByteString -&gt; BuiltinString in this case or is it a special byte string?</p>

CC BY-SA 4.0
2022-02-18T08:01:12.603Z
Both wallets call mint endpoint and if you explicitly allow only one of the wallets to mint then it will of course throw error. Try removing or commenting the other wallet's call to endpoint.
Tuvshintsenguun
CC BY-SA 4.0
2022-02-18T09:25:18.537Z
@Tuvshintsenguun thanks, forgot to mention this: the EmulatorTrace was adjusted to only have 1 mint call from wallet 1.
DaveStrider
<plutus-pioneer-program><error><week05>
Onchain validation fails for hard-coded pkh
# Onchain validation fails for hard-coded pkh

(Asked by: username_0 on 2022-02-18)

When modifying the week5 code in e.g. Signed.hs from
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ unPaymentPubKeyHash pkh

to the hard-coded pkh from Wallet 1,
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ PubKeyHash "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2"

the validation fails with
CONTRACT STOPPED WITH ERROR: "\"WalletError (ValidationError (ScriptFailure (EvaluationError [\\\"PT5\\\"] \\\"CekEvaluationFailure\\\")))\""

I verified in the repl:
mockWalletPaymentPubKeyHash (knownWallet 1)
a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2

and also in the offchain code logging Contract.ownPaymentPubKeyHash gives the same a2c2...09c2 hash.
What is going wrong here?
I unsuccessfully tried to debug it with
mkPolicy pkh () ctx = traceError $ decodeUtf8 $ getPubKeyHash $ head $ txInfoSignatories (scriptContextTxInfo ctx)

which resulted in an error as well.
CONTRACT STOPPED WITH ERROR: "\"WalletError (ValidationError (ScriptFailure (EvaluationError [] \\\"BuiltinEvaluationFailure of DecodeUtf8\\\")))\""

What is the correct way to debug this? e.g. in this case to check what the pkh used in the onchain code was? Is decodeUtf8 the right function at all for BuiltinByteString -> BuiltinString in this case or is it a special byte string?

**Tags:** plutus-pioneer-program, error, week05
> **Comments:**
> **username_1**: Both wallets call mint endpoint and if you explicitly allow only one of the wallets to mint then it will of course throw error. Try removing or commenting the other wallet's call to endpoint.  
> **username_0**: @Tuvshintsenguun thanks, forgot to mention this: the EmulatorTrace was adjusted to only have 1 mint call from wallet 1.  

---

## 1 answers

### Answer by username_0 on 2022-03-03. Score: 2

This was answered in PPP Q&A, the issue was the string literals in Plutus Core code.
Instead, one has to use variables
{-# INLINABLE mkPolicy #-}
mkPolicy :: PaymentPubKeyHash -> () -> ScriptContext -> Bool
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ 
unPaymentPubKeyHash pkh

and put the literal into the liftCode expression:
policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $
$$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
`PlutusTx.applyCode`
PlutusTx.liftCode (PaymentPubKeyHash "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2")


---

