<p>I am trying to consume old UTXO at stript and produce new one with new Datum.
Validator is validating ok but not sure why new utxo with updated datum is not available.</p>
<p>current utxos holds one utxo with Datum DAccept</p>
<p>this is how i am constructing tx</p>
<pre><code>let tx = collectFromScript  utxos redeemer  &lt;&gt;  Constraints.mustPayToTheScript DRecv tAmt   
</code></pre>
<p>TxConstraint looks something like this</p>
<pre><code>TxConstraints {
  txConstraints = [MustIncludeDatum (Datum {getDatum = Constr 2 []})], # constr 2 = DRecv 
  txOwnInputs = [
     InputConstraint {icRedeemer = ReceiveItem \&quot;key_C1\&quot;, icTxOutRef = TxOutRef {
       txOutRefId = a3d3cac6f6c2c2c9152baaa97e1f807dbdeee3ff7f1b47d0cfc1d3b6329091e5, txOutRefIdx = 1}
     }], 
   txOwnOutputs = [
      OutputConstraint {ocDatum = DRecv, ocValue = Value (Map [(,Map [(\&quot;\&quot;,20000000)])])}
   ]
}
</code></pre>
<p>Redeemer looks something like this</p>
<pre><code> ReceiveItem k -&gt;                                                                                                                                                                        
   traceIfFalse  &quot;Must output DRecv datum&quot; (isScriptOpHasDatum DRecv)  &amp;&amp;                                                                                                                
   traceIfFalse  &quot;Must have Datum&quot; (dtm == DAccept)  &amp;&amp;                                                                                                                         
</code></pre>
<pre><code> scriptOutput :: TxOut                                                                                                                                                                   
 scriptOutput = case getContinuingOutputs ctx of                                                                                                                                         
   [o] -&gt; o                                                                                                                                                                              
     _ -&gt; traceError &quot;More than one outputs&quot;                                                                                                                                               
                                                                                                                                                                                            
 scriptOutputDtm :: Maybe  DeliveryStatus                                                                                                                                                
     scriptOutputDtm = do                                                                                                                                                                    
       dtmHash &lt;-  txOutDatum  scriptOutput                                                                                                                                                  
      Datum d &lt;-  findDatum dtmHash info                                                                                                                                                    
                                                                                                                                                                                           
     PlutusTx.fromBuiltinData  d                                                                                                                                                           
                                                                                                                                                                                            
 isScriptOpHasDatum :: DeliveryStatus -&gt; Bool                                                                                                                                            
 isScriptOpHasDatum d = scriptOutputDtm  == Just d
</code></pre>
<p>above redeemer is working fine but tx is not producing new output with <code>DRecv</code> Datum</p>

CC BY-SA 4.0
2022-06-26T09:46:52.790Z
could you please share what the ```isScriptOpHasDatum``` function is doing?
Michele Nuzzi
CC BY-SA 4.0
2022-06-26T10:03:21.360Z
@Michele sure its just checks if datum is there in output. added code
Piyush
CC BY-SA 4.0
2022-06-26T20:32:05.433Z
Issue was in another validation i was not calculating inputs correctly, its solved now thanks.
Piyush
CC BY-SA 4.0
2022-06-27T09:52:09.687Z
Hi Piyush, it will help us a lot if you can share with the community the solution to your problem in a post. Thank you.
Falcon Stakepool
CC BY-SA 4.0
2022-07-19T17:20:07.557Z
my issue was i didn't log much Trace in TraceConfig so it was not giving another TraceError above code is fine
Piyush
<plutus><eutxo>
How to consume and produce new UTXO to same script with different Datum?
# How to consume and produce new UTXO to same script with different Datum?

(Asked by: username_0 on 2022-06-26)

I am trying to consume old UTXO at stript and produce new one with new Datum.
Validator is validating ok but not sure why new utxo with updated datum is not available.
current utxos holds one utxo with Datum DAccept
this is how i am constructing tx
let tx = collectFromScript  utxos redeemer  <>  Constraints.mustPayToTheScript DRecv tAmt   

TxConstraint looks something like this
TxConstraints {
  txConstraints = [MustIncludeDatum (Datum {getDatum = Constr 2 []})], # constr 2 = DRecv 
  txOwnInputs = [
     InputConstraint {icRedeemer = ReceiveItem \"key_C1\", icTxOutRef = TxOutRef {
       txOutRefId = a3d3cac6f6c2c2c9152baaa97e1f807dbdeee3ff7f1b47d0cfc1d3b6329091e5, txOutRefIdx = 1}
     }], 
   txOwnOutputs = [
      OutputConstraint {ocDatum = DRecv, ocValue = Value (Map [(,Map [(\"\",20000000)])])}
   ]
}

Redeemer looks something like this
 ReceiveItem k ->                                                                                                                                                                        
   traceIfFalse  "Must output DRecv datum" (isScriptOpHasDatum DRecv)  &&                                                                                                                
   traceIfFalse  "Must have Datum" (dtm == DAccept)  &&                                                                                                                         

 scriptOutput :: TxOut                                                                                                                                                                   
 scriptOutput = case getContinuingOutputs ctx of                                                                                                                                         
   [o] -> o                                                                                                                                                                              
     _ -> traceError "More than one outputs"                                                                                                                                               
                                                                                                                                                                                            
 scriptOutputDtm :: Maybe  DeliveryStatus                                                                                                                                                
     scriptOutputDtm = do                                                                                                                                                                    
       dtmHash <-  txOutDatum  scriptOutput                                                                                                                                                  
      Datum d <-  findDatum dtmHash info                                                                                                                                                    
                                                                                                                                                                                           
     PlutusTx.fromBuiltinData  d                                                                                                                                                           
                                                                                                                                                                                            
 isScriptOpHasDatum :: DeliveryStatus -> Bool                                                                                                                                            
 isScriptOpHasDatum d = scriptOutputDtm  == Just d

above redeemer is working fine but tx is not producing new output with DRecv Datum

**Tags:** plutus, eutxo
> **Comments:**
> **username_1**: could you please share what the ```isScriptOpHasDatum``` function is doing?  
> **username_0**: @Michele sure its just checks if datum is there in output. added code  
> **username_0**: Issue was in another validation i was not calculating inputs correctly, its solved now thanks.  
> **username_2**: Hi Piyush, it will help us a lot if you can share with the community the solution to your problem in a post. Thank you.  
> **username_0**: my issue was i didn't log much Trace in TraceConfig so it was not giving another TraceError above code is fine  

---

## 0 answers

