<p>There are two options</p>
<pre><code>--invalid-before SLOT    Time that transaction is valid from (in slots).
--invalid-hereafter SLOT Time that transaction is valid until (in slots).
</code></pre>
<p>In you example you would use <code>--invalid-before $CURENT_TIME_SLOT</code></p>

CC BY-SA 4.0
2022-02-14T23:33:46.993Z
Thanks to both of you. --invalid-before SLOT worked perfectly!
Gary Alexander
CC BY-SA 4.0
2022-02-14T23:35:39.107Z
I'd upvote both answers, but I only have an 11 reputation - need 15. I'll come back and do it when I get there. Thanks again!!!
Gary Alexander
CC BY-SA 4.0
2022-02-14T23:42:13.293Z
@GaryAlexander Even so, I think you can mark one of those how the most useful.
kindofdev
CC BY-SA 4.0
2022-02-14T21:43:19.460Z
2022-02-14T21:43:19.460Z
Kaliman
<p>At the time to build a transaction with <strong>cardano-cli</strong> using the command <strong>cardano-cli transaction build</strong>, you can use the input parameters <strong>--invalid-before SLOT</strong> or <strong>--invalid-hereafter SLOT</strong> where <strong>invalid-before refers</strong> to the time that transaction is valid from (in slots), and <strong>invalid-hereafter</strong> to the time that transaction is valid until (in slots).</p>
<p>Notice that if you don't set a valid range the default will be &quot;all the time&quot;.</p>
<p><a href="https://i.sstatic.net/vytnm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vytnm.png" alt="enter image description here" /></a></p>
<p>You can get this info using <code>cardano-cli transaction build --help</code></p>
<p>An example of this would be the following command (shown by Lars in lecture 3). Check <a href="https://github.com/kindofdev/plutus-pioneer-program-iter3/blob/main/code/week03/testnet/grab.sh" rel="nofollow noreferrer">https://github.com/kindofdev/plutus-pioneer-program-iter3/blob/main/code/week03/testnet/grab.sh</a></p>
<pre><code>cardano-cli transaction build \
    --alonzo-era \
    --testnet-magic 1097911063 \
    --change-address $(cat 02.addr) \
    --tx-in 18cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef#1 \
    --tx-in-script-file vesting.plutus \
    --tx-in-datum-file unit.json \
    --tx-in-redeemer-file unit.json \
    --tx-in-collateral 18e93407ea137b6be63039fd3c564d4c5233e7eb7ce4ee845bc7df12c80e4df7#1 \
    --required-signer-hash c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a \
    --invalid-before 48866954 \
    --protocol-params-file protocol.json \
    --out-file tx.body 
</code></pre>
<p>here the tx is invalid before slot 48866954. In plutus:</p>
<p><code>Constraints.mustValidateIn $ from $ slotToBeginPOSIXTime def 48866954</code></p>
<p>In your case you should use <code>--invalid-before $CURRENT_TIME_SLOT</code></p>
<p>If you are wondering how to get a slot number for Cardano testnet given a <strong>posixtime</strong>, here you have a way to do it.</p>
<p><a href="https://cardano.stackexchange.com/questions/7034/how-to-convert-posixtime-to-slot-number-on-cardano-testnet">How to convert posixTime to slot number on Cardano Testnet</a></p>

CC BY-SA 4.0
2022-02-14T21:47:16.423Z
2022-02-14T22:34:40.947Z
2022-02-14T22:34:40.947Z
kindofdev
<p>How does txInfoValidRange get set on the testnet?</p>
<p>I've been made aware that on the Plutus Playground
a piece of off-chain code:
&quot;Constraints.mustValidateIn (from now)&quot; will
set txInfoValidRange (works great).</p>
<p>I'm looking for the equivalent cardano-cli command
for &quot;Constraints.mustValidateIn (from now)&quot;,
that will set the txInfoValidRange properly on
the testnet?</p>

<cardano-cli><testnet><txinfovalidrange>
How do I set txInfoValidRange on the testnet using cardano-cli
# How do I set txInfoValidRange on the testnet using cardano-cli

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

How does txInfoValidRange get set on the testnet?

I've been made aware that on the Plutus Playground
a piece of off-chain code:
"Constraints.mustValidateIn (from now)" will
set txInfoValidRange (works great).

I'm looking for the equivalent cardano-cli command
for "Constraints.mustValidateIn (from now)",
that will set the txInfoValidRange properly on
the testnet?

**Tags:** cardano-cli, testnet, txinfovalidrange

---

## 2 answers

### Answer by username_1 on 2022-02-14. Score: 1

There are two options
--invalid-before SLOT    Time that transaction is valid from (in slots).
--invalid-hereafter SLOT Time that transaction is valid until (in slots).

In you example you would use --invalid-before $CURENT_TIME_SLOT

> **Comments:**
> **username_0**: Thanks to both of you. --invalid-before SLOT worked perfectly!  
> **username_0**: I'd upvote both answers, but I only have an 11 reputation - need 15. I'll come back and do it when I get there. Thanks again!!!  
> **username_2**: @GaryAlexander Even so, I think you can mark one of those how the most useful.  

---

### Answer by username_2 on 2022-02-14. Score: 1

At the time to build a transaction with cardano-cli using the command cardano-cli transaction build, you can use the input parameters --invalid-before SLOT or --invalid-hereafter SLOT where invalid-before refers to the time that transaction is valid from (in slots), and invalid-hereafter to the time that transaction is valid until (in slots).
Notice that if you don't set a valid range the default will be "all the time".

You can get this info using cardano-cli transaction build --help
An example of this would be the following command (shown by Lars in lecture 3). Check https://github.com/kindofdev/plutus-pioneer-program-iter3/blob/main/code/week03/testnet/grab.sh
cardano-cli transaction build \
    --alonzo-era \
    --testnet-magic 1097911063 \
    --change-address $(cat 02.addr) \
    --tx-in 18cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef#1 \
    --tx-in-script-file vesting.plutus \
    --tx-in-datum-file unit.json \
    --tx-in-redeemer-file unit.json \
    --tx-in-collateral 18e93407ea137b6be63039fd3c564d4c5233e7eb7ce4ee845bc7df12c80e4df7#1 \
    --required-signer-hash c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a \
    --invalid-before 48866954 \
    --protocol-params-file protocol.json \
    --out-file tx.body 

here the tx is invalid before slot 48866954. In plutus:
Constraints.mustValidateIn $ from $ slotToBeginPOSIXTime def 48866954
In your case you should use --invalid-before $CURRENT_TIME_SLOT
If you are wondering how to get a slot number for Cardano testnet given a posixtime, here you have a way to do it.
How to convert posixTime to slot number on Cardano Testnet


---

