2

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?

2 Answers 2

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

3
  • Thanks to both of you. --invalid-before SLOT worked perfectly! Feb 14 at 23:33
  • 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!!! Feb 14 at 23:35
  • @GaryAlexander Even so, I think you can mark one of those how the most useful.
    – kindofdev
    Feb 14 at 23:42
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".

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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