<p>For plutus v2 you have to differentiate since inline datums could be present at a given output.</p>
<pre><code>outputDatumByHash :: DatumHash -&gt; Maybe Datum
outputDatumByHash h = findDatum h info

ownOutputDatum :: TxOut -&gt; Maybe TransferDatum
ownOutputDatum TxOut{txOutDatum=OutputDatumHash h} = transferDatum $ outputDatumByHash h
ownOutputDatum _                                   = Nothing

outputDatum :: TxOut -&gt; TransferDatum
outputDatum txOut = case ownOutputDatum txOut of
    Nothing -&gt; traceError &quot;Transfer output datum not found&quot;
    Just d  -&gt; d
</code></pre>

CC BY-SA 4.0
2022-10-11T11:59:19.973Z
2022-10-11T11:59:19.973Z
Will
<p>Looking at the API:</p>
<p>V1's <code>TxOut</code> uses <code>txOutDatumHash :: Maybe DatumHash</code></p>
<p>V2's <code>TxOut</code> uses <code>txOutDatum :: OutputDatum</code>
where <code>data OutputDatum = NoOutputDatum | OutputDatumHash DatumHash | OutputDatum Datum</code></p>
<p>So V2 still has DatumHash but you need to also handle the possibility of OutputDatum (inline datum).</p>

CC BY-SA 4.0
2022-10-11T09:18:16.680Z
2022-10-11T09:18:16.680Z
james
<p>The following code would work for V1:
outputDatum :: EkivalEscrowDatum</p>
<pre><code>outputDatum = case transferDatum $ txOutDatumHash ownOutput &gt;&gt;= flip findDatum info of

    Nothing -&gt; traceError &quot;Transfer output datum not found&quot;

    Just d  -&gt; d
</code></pre>
<p>However, &quot;txOutDatumHash&quot; seems to be missing a corresponding implementation in V2.
I understand we may face inline Datum, which would not include the Hash, but backward compatibility appears to not be fully implemented on this function.
From the plutus-apps examples, I noticed a mixture of V1 modules whenever the datum was being verified.
PS: transferDatum :: Maybe Datum -&gt; Maybe EkivalEscrowDatum</p>

<plutus-pioneer-program>
How to check the output datum reference in V2
# How to check the output datum reference in V2

(Asked by: username_0 on 2022-10-11)

The following code would work for V1:
outputDatum :: EkivalEscrowDatum
outputDatum = case transferDatum $ txOutDatumHash ownOutput >>= flip findDatum info of

    Nothing -> traceError "Transfer output datum not found"

    Just d  -> d

However, "txOutDatumHash" seems to be missing a corresponding implementation in V2.
I understand we may face inline Datum, which would not include the Hash, but backward compatibility appears to not be fully implemented on this function.
From the plutus-apps examples, I noticed a mixture of V1 modules whenever the datum was being verified.
PS: transferDatum :: Maybe Datum -> Maybe EkivalEscrowDatum

**Tags:** plutus-pioneer-program

---

## 2 answers

### Answer by username_1 on 2022-10-11. Score: 0 | Accepted answer

For plutus v2 you have to differentiate since inline datums could be present at a given output.
outputDatumByHash :: DatumHash -> Maybe Datum
outputDatumByHash h = findDatum h info

ownOutputDatum :: TxOut -> Maybe TransferDatum
ownOutputDatum TxOut{txOutDatum=OutputDatumHash h} = transferDatum $ outputDatumByHash h
ownOutputDatum _                                   = Nothing

outputDatum :: TxOut -> TransferDatum
outputDatum txOut = case ownOutputDatum txOut of
    Nothing -> traceError "Transfer output datum not found"
    Just d  -> d


---

### Answer by username_2 on 2022-10-11. Score: 1

Looking at the API:

V1's `TxOut` uses `txOutDatumHash :: Maybe DatumHash`

V2's `TxOut` uses `txOutDatum :: OutputDatum`
where `data OutputDatum = NoOutputDatum | OutputDatumHash DatumHash | OutputDatum Datum`

So V2 still has DatumHash but you need to also handle the possibility of OutputDatum (inline datum).


---

