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?

  • 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 Commented Jun 14, 2022 at 21:16
  • 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
    Commented Jun 15, 2022 at 13:32

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.