user5844: I have attached a token to the datum and sent it to the smart contract, now I need the validator to check that the token has a certain policy ID before it allows the contract to proceed.
How do I do that?

user2335: You can use the following
info :: TxInfo
info = scriptContextTxInfo ctx

inputValue :: [Value]
inputValue = map (txOutValue . txInInfoResolved) (txInfoInputs info)

checkValueHasToken :: Value -> Bool
checkValueHasToken val = case flattenValue val of
        (pol, tn, amt) -> pol == knownPolicyID 

checkInputHasToken :: Bool
checkInputHasToken = any checkValueHashToken inputValue



5844: <p>I have attached a token to the datum and sent it to the smart contract, now I need the validator to check that the token has a certain policy ID before it allows the contract to proceed.</p>
<p>How do I do that?</p>
 2335: <p>You can use the following</p>
<pre><code>info :: TxInfo
info = scriptContextTxInfo ctx

inputValue :: [Value]
inputValue = map (txOutValue . txInInfoResolved) (txInfoInputs info)

checkValueHasToken :: Value -&gt; Bool
checkValueHasToken val = case flattenValue val of
        (pol, tn, amt) -&gt; pol == knownPolicyID 

checkInputHasToken :: Bool
checkInputHasToken = any checkValueHashToken inputValue

</code></pre>
