<p>When creating a transaction that will consume a script that contains a before you need to add &quot; --invalid-after&quot; to your transaction.</p>
<p>In your case in would look something like :</p>
<pre><code>cardano-cli transaction build \
--babbage-era \
--testnet-magic 1 \
--tx-in 95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a#0 \
--tx-out $(cat P1.addr)+2000000+&quot;1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031&quot; \
--change-address $(cat P1.addr) \
--mint=&quot;1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031&quot; \
--mint-script-file policy.script \
--invalid-after 16670000 \
--witness-override '2' \
--out-file tx.raw
</code></pre>

CC BY-SA 4.0
2023-01-08T18:05:49.800Z
2023-01-08T18:05:49.800Z
Leo
<p>I am trying to mint an NFT for the zeroOneGame exercise from gimbalabs on the pre-production testnet (babbage-era) but I incur in an error and I can't see what I am doing wrong.
Here are the steps that I am taking:</p>
<p>I create <code>P1.vkey</code> and <code>P1.skey</code> and then build the payment address <code>P1.addr</code>.</p>
<p>I create <code>policy.vkey</code> and <code>policy.skey</code> and then get the hash key for <code>policy.vkey</code></p>
<pre><code>cardano-cli address key-hash --payment-verification-key-file policy.vkey
&gt; c1ed1f20dee68e6c10a863a5058ff9b44b0ad37f409c38a50fd38f51
</code></pre>
<p>I ask for the current slot</p>
<pre><code>{
    &quot;block&quot;: 458153,
    &quot;epoch&quot;: 42,
    &quot;era&quot;: &quot;Babbage&quot;,
    &quot;hash&quot;: &quot;e4a4ca5c206829d30112a0ed8c95813218d3ccf1713811236081ce2e4933c001&quot;,
    &quot;slot&quot;: 16656970,
    &quot;syncProgress&quot;: &quot;100.00&quot;
}
</code></pre>
<p>Now I can create the <code>policy.script</code></p>
<pre><code>{
  &quot;type&quot;: &quot;all&quot;,
  &quot;scripts&quot;:
  [
    {
      &quot;type&quot;: &quot;before&quot;,
      &quot;slot&quot;: 16670000 
    },
    {
      &quot;type&quot;: &quot;sig&quot;,
      &quot;keyHash&quot;: &quot;c1ed1f20dee68e6c10a863a5058ff9b44b0ad37f409c38a50fd38f51&quot;
    }
  ]
}
</code></pre>
<p>Now I can create the <code>policyID</code></p>
<pre><code>cardano-cli transaction policyid --script-file policy.script
&gt; 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8
</code></pre>
<p>In the meantime the <code>P1.addr</code> was funded obtanining the following UTxO</p>
<pre><code>cardano-cli query utxo --address $(cat P1.addr) --testnet-magic 1
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a     0        997833047 lovelace + TxOutDatumNone
</code></pre>
<p>I can now build the <code>tx.raw</code> for the minting of my NFT.</p>
<pre><code>cardano-cli transaction build \
--babbage-era \
--testnet-magic 1 \
--tx-in 95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a#0 \
--tx-out $(cat P1.addr)+2000000+&quot;1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031&quot; \
--change-address $(cat P1.addr) \
--mint=&quot;1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031&quot; \
--mint-script-file policy.script \
--witness-override '2' \
--out-file tx.raw
</code></pre>
<p>and finally sign it and submit it</p>
<pre><code>cardano-cli transaction sign  \
--signing-key-file P1.skey  \
--signing-key-file policy.skey  \
--testnet-magic 1 \
--tx-body-file tx.raw  \
--out-file tx.signed
</code></pre>
<pre><code>cardano-cli transaction submit --tx-file tx.signed --testnet-magic 1
</code></pre>
<p>Everything seem correct to me, but unfortunately at this point I get the following error from the <code>cardano-cli</code></p>
<pre><code>Command failed: transaction submit
Error: Error while submitting 
tx: ShelleyTxValidationError 
  ShelleyBasedEraBabbage (
    ApplyTxError [
      UtxowFailure (
        FromAlonzoUtxowFail (
          WrappedShelleyEraFailure (
            ScriptWitnessNotValidatingUTXOW (
              fromList [
                ScriptHash &quot;0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8&quot;
              ]
            )
          )
        )
      )
    ]
  )
</code></pre>
<p>The script witness is not validating the script, yet I have put the right hash of the right <code>policy.vkey</code> in the <code>policy.script</code>, and I am signing the transaction with the relative <code>policy.skey</code>. So the witness should validate the script, why is that not the case?</p>
<p>I see that it mentions something about <code>WrappedShelleyEraFailure</code>, is that something to do with the fact I am not using the right commands for the Babbage era?</p>
<p>Also what is the &quot;W&quot; in the UTXO in <code>ScriptWitnessNotValidatingUTXOW</code> and <code>FromAlonzoUtxowFail</code> indicating?</p>
<p><strong>UPDATE</strong></p>
<p>It seem that the problem was in the script itself. I removed the lines regarding the slot number:</p>
<pre><code>    {
      &quot;type&quot;: &quot;before&quot;,
      &quot;slot&quot;: 16670000 
    },
</code></pre>
<p>and the transaction went through creating the token, although without the time limit it is not an NFT.
But well it also changes the nature of my question:
Why my time limit instruction isn't working?</p>

<cardano-cli><transaction><minting><mintingpolicy>
ScriptWitnessNotValidatingUTXOW - Transaction Error While Minting NFT With Native Script - Before Slot Instruction Not Working
# ScriptWitnessNotValidatingUTXOW - Transaction Error While Minting NFT With Native Script - Before Slot Instruction Not Working

(Asked by: username_0 on 2022-12-29)

I am trying to mint an NFT for the zeroOneGame exercise from gimbalabs on the pre-production testnet (babbage-era) but I incur in an error and I can't see what I am doing wrong.
Here are the steps that I am taking:

I create `P1.vkey` and `P1.skey` and then build the payment address `P1.addr`.

I create `policy.vkey` and `policy.skey` and then get the hash key for `policy.vkey`

```
cardano-cli address key-hash --payment-verification-key-file policy.vkey
> c1ed1f20dee68e6c10a863a5058ff9b44b0ad37f409c38a50fd38f51

```

I ask for the current slot

```
{
    "block": 458153,
    "epoch": 42,
    "era": "Babbage",
    "hash": "e4a4ca5c206829d30112a0ed8c95813218d3ccf1713811236081ce2e4933c001",
    "slot": 16656970,
    "syncProgress": "100.00"
}

```

Now I can create the `policy.script`

```
{
  "type": "all",
  "scripts":
  [
    {
      "type": "before",
      "slot": 16670000 
    },
    {
      "type": "sig",
      "keyHash": "c1ed1f20dee68e6c10a863a5058ff9b44b0ad37f409c38a50fd38f51"
    }
  ]
}

```

Now I can create the `policyID`

```
cardano-cli transaction policyid --script-file policy.script
> 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8

```

In the meantime the `P1.addr` was funded obtanining the following UTxO

```
cardano-cli query utxo --address $(cat P1.addr) --testnet-magic 1
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a     0        997833047 lovelace + TxOutDatumNone

```

I can now build the `tx.raw` for the minting of my NFT.

```
cardano-cli transaction build \
--babbage-era \
--testnet-magic 1 \
--tx-in 95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a#0 \
--tx-out $(cat P1.addr)+2000000+"1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031" \
--change-address $(cat P1.addr) \
--mint="1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031" \
--mint-script-file policy.script \
--witness-override '2' \
--out-file tx.raw

```

and finally sign it and submit it

```
cardano-cli transaction sign  \
--signing-key-file P1.skey  \
--signing-key-file policy.skey  \
--testnet-magic 1 \
--tx-body-file tx.raw  \
--out-file tx.signed

```

```
cardano-cli transaction submit --tx-file tx.signed --testnet-magic 1

```

Everything seem correct to me, but unfortunately at this point I get the following error from the `cardano-cli`

```
Command failed: transaction submit
Error: Error while submitting 
tx: ShelleyTxValidationError 
  ShelleyBasedEraBabbage (
    ApplyTxError [
      UtxowFailure (
        FromAlonzoUtxowFail (
          WrappedShelleyEraFailure (
            ScriptWitnessNotValidatingUTXOW (
              fromList [
                ScriptHash "0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8"
              ]
            )
          )
        )
      )
    ]
  )

```

The script witness is not validating the script, yet I have put the right hash of the right `policy.vkey` in the `policy.script`, and I am signing the transaction with the relative `policy.skey`. So the witness should validate the script, why is that not the case?

I see that it mentions something about `WrappedShelleyEraFailure`, is that something to do with the fact I am not using the right commands for the Babbage era?

Also what is the "W" in the UTXO in `ScriptWitnessNotValidatingUTXOW` and `FromAlonzoUtxowFail` indicating?

**UPDATE**

It seem that the problem was in the script itself. I removed the lines regarding the slot number:

```
    {
      "type": "before",
      "slot": 16670000 
    },

```

and the transaction went through creating the token, although without the time limit it is not an NFT.
But well it also changes the nature of my question:
Why my time limit instruction isn't working?

**Tags:** cardano-cli, transaction, minting, mintingpolicy


---

## 1 answers

### Answer by username_1 on 2023-01-08. Score: 0 | Accepted answer

When creating a transaction that will consume a script that contains a before you need to add " --invalid-after" to your transaction.

In your case in would look something like :

```
cardano-cli transaction build \
--babbage-era \
--testnet-magic 1 \
--tx-in 95ebaeb5d47bf28842e7551ca467415cfae12f466239b59e90c532405ab88e3a#0 \
--tx-out $(cat P1.addr)+2000000+"1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031" \
--change-address $(cat P1.addr) \
--mint="1 0de56a658ba5838183a57f6260d8f2919c8350b2186609ebd986cfa8.7a65726f4f6e6547616d65546573743031" \
--mint-script-file policy.script \
--invalid-after 16670000 \
--witness-override '2' \
--out-file tx.raw

```


---

