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

CC BY-SA 4.0
2022-07-13T07:54:18.020Z
2022-07-13T08:25:14.293Z
2022-07-13T08:25:14.293Z
Fermat
<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>

CC BY-SA 4.0
2022-06-14T21:16:57.640Z
How did you attach the token to the datum? did you do something like ```<policy id>.<token name>``` as a ```BuiltinByteString``` ? I'm asking since the Datum is supposed to only have data
Michele Nuzzi
CC BY-SA 4.0
2022-06-15T13:32:38.173Z
Please check the answer to my previous question. Someone told me to send along the token with the datum maybe attached isn't the right word but I don't know what would be.
KryptoKing
<token><smart-contract><policy><mkvalidator>
How to Look Up a Token Policy ID from The Smart Contract Validator
# How to Look Up a Token Policy ID from The Smart Contract Validator

(Asked by: username_0 on 2022-06-10)

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?

**Tags:** token, smart-contract, policy, mkvalidator
> **Comments:**
> **username_1**: How did you attach the token to the datum? did you do something like ```<policy id>.<token name>``` as a ```BuiltinByteString``` ? I'm asking since the Datum is supposed to only have data  
> **username_0**: Please check the answer to my previous question. Someone told me to send along the token with the datum maybe attached isn't the right word but I don't know what would be.  

---

## 1 answers

### Answer by username_2 on 2022-07-13. Score: 1 | Accepted answer

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


---

