user5605: I am trying to make a minting policy that fails after a certain deadline.
I have tried something like this
{-# INLINABLE mkTokenPolicy #-}
mkTokenPolicy :: TxOutRef -> TokenName -> Integer -> () -> ScriptContext -> Bool
mkTokenPolicy oref tn amt () ctx = traceIfFalse "Deadline reached"   checkDeadline         && --getinng error that oef isnt even used
                                   traceIfFalse "wrong amount minted" checkMintedAmount
  where
    info :: TxInfo
    info = scriptContextTxInfo ctx

    checkDeadline:: Bool
    checkDeadline = ivTo (from mDeadline) >  ivTo (txInfoValidRange info)                        
        where
            mDeadline ::  POSIXTime
            mDeadline =  1680120281000

    checkMintedAmount :: Bool
    checkMintedAmount = case flattenValue (txInfoMint info) of
        [(_, tn', amt')] -> tn' == tn && amt' == amt
        _                -> False 

and have also tried something like this
{-# INLINABLE mkTokenPolicy #-}
mkTokenPolicy :: TxOutRef -> TokenName -> Integer -> () -> ScriptContext -> Bool
mkTokenPolicy oref tn amt () ctx = traceIfFalse "Deadline reached"   checkDeadline         && --getinng error that oef isnt even used
                                   traceIfFalse "wrong amount minted" checkMintedAmount
  where
    info :: TxInfo
    info = scriptContextTxInfo ctx

    checkDeadline:: Bool
    checkDeadline = to mDeadline `contains` txInfoValidRange info                       
        where
            mDeadline ::  POSIXTime
            mDeadline =  1680120281000

    checkMintedAmount :: Bool
    checkMintedAmount = case flattenValue (txInfoMint info) of
        [(_, tn', amt')] -> tn' == tn && amt' == amt
        _                -> False 

However, no matter what I seem to do, checkDeadline always returns False. Does anyone have any thoughts on how I can fix this?

user1130: Make sure you are adding your time constraints in your off-chain code as well.
Here is an example of the constraints in the auction contract.
Background:
This can be kinda unintuitive to some people, but essentially the script doesn't know when it's executing, it just has the context from the transaction.
When you use Constraints.mustValidateIn X off chain, you are building a tx that is valid over X range. If you submit it outside of that range, it will fail before it ever gets to a validator script.
Say your script only accepts txs that are valid in range 5-10 and your tx is valid in range 1-10. Even if it occurs on 7, it will still fail the validator!
Script constraints are looking at the range a tx is valid, with the implicit assertion that it is being executed in that range (or else it wouldn't have made it to the script). That way, the script doesn't need to know which slot it is currently and can be deterministic. The non-deterministic stuff is cleanly separated from the pure scripts.

5605: <p>I am trying to make a minting policy that fails after a certain deadline.</p>
<p>I have tried something like this</p>
<pre><code>{-# INLINABLE mkTokenPolicy #-}
mkTokenPolicy :: TxOutRef -&gt; TokenName -&gt; Integer -&gt; () -&gt; ScriptContext -&gt; Bool
mkTokenPolicy oref tn amt () ctx = traceIfFalse &quot;Deadline reached&quot;   checkDeadline         &amp;&amp; --getinng error that oef isnt even used
                                   traceIfFalse &quot;wrong amount minted&quot; checkMintedAmount
  where
    info :: TxInfo
    info = scriptContextTxInfo ctx

    checkDeadline:: Bool
    checkDeadline = ivTo (from mDeadline) &gt;  ivTo (txInfoValidRange info)                        
        where
            mDeadline ::  POSIXTime
            mDeadline =  1680120281000

    checkMintedAmount :: Bool
    checkMintedAmount = case flattenValue (txInfoMint info) of
        [(_, tn', amt')] -&gt; tn' == tn &amp;&amp; amt' == amt
        _                -&gt; False 
</code></pre>
<p>and have also tried something like this</p>
<pre><code>{-# INLINABLE mkTokenPolicy #-}
mkTokenPolicy :: TxOutRef -&gt; TokenName -&gt; Integer -&gt; () -&gt; ScriptContext -&gt; Bool
mkTokenPolicy oref tn amt () ctx = traceIfFalse &quot;Deadline reached&quot;   checkDeadline         &amp;&amp; --getinng error that oef isnt even used
                                   traceIfFalse &quot;wrong amount minted&quot; checkMintedAmount
  where
    info :: TxInfo
    info = scriptContextTxInfo ctx

    checkDeadline:: Bool
    checkDeadline = to mDeadline `contains` txInfoValidRange info                       
        where
            mDeadline ::  POSIXTime
            mDeadline =  1680120281000

    checkMintedAmount :: Bool
    checkMintedAmount = case flattenValue (txInfoMint info) of
        [(_, tn', amt')] -&gt; tn' == tn &amp;&amp; amt' == amt
        _                -&gt; False 
</code></pre>
<p>However, no matter what I seem to do, checkDeadline always returns False. Does anyone have any thoughts on how I can fix this?</p>
 1130: <p>Make sure you are adding your time constraints in your off-chain code as well.</p>
<p><a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/28559d379df8b66c06d8fbd1e2a43f6a8351382a/code/week01/src/Week01/EnglishAuction.hs" rel="nofollow noreferrer">Here</a> is an example of the constraints in the auction contract.</p>
<p><strong>Background:</strong></p>
<p>This can be kinda unintuitive to some people, but essentially the script doesn't know <em>when</em> it's executing, it just has the context from the transaction.</p>
<p>When you use <code>Constraints.mustValidateIn X</code> off chain, you are building a tx that is valid over X range. If you submit it outside of that range, it will fail before it ever gets to a validator script.</p>
<p>Say your script only accepts txs that are valid in range 5-10 and your tx is valid in range 1-10. Even if it occurs on 7, it will still fail the validator!</p>
<p>Script constraints are looking at the range a tx is valid, with the implicit assertion that it is being executed in that range (or else it wouldn't have made it to the script). That way, the script doesn't need to know which slot it is currently and can be deterministic. The non-deterministic stuff is cleanly separated from the pure scripts.</p>
