user6113: I'm trying to understand how Constraints.mustHashDatum works but I'm not able to figure out the purpose of this Constraint.
Any help would be great.

user5788: This is my beginner takeaway about Constraints.mustHashDatum after reading about TxContraints and TxConstraint and mustHashDatum at the Ledger.Constraints documentation link below.  I will also be interested in the responses so that I can know the answer too.
Here are my thoughts.  It seems like when we're creating a transaction, we can dictate that one of the constraints/requirements is just that there exist a Datum and a DatumHash, and that both must be supplied as part of transaction creation.  If one or both is not supplied, then the transaction won't be generated because the particular mustHashDatum constraint wouldn't be met. I think maybe the mustHashDatum constraint does this for us, since just creating that constraint requires that we provide both. Presumably, we might set this as a constraint to make sure that later code involving the transaction can use/check the Datum and the DatumHash.
Below are the excerpts from the documentation that seemed applicable.
https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-constraints/html/Ledger-Constraints.html
Ledger.Constraints
This module defines TxConstraints, a list of constraints on transactions. To construct a value of TxConstraints use the mustPayToTheScript, mustSpendAtLeast, etc functions. Once we have a TxConstraints value it can be used both to generate a transaction that satisfies the constraints (off-chain, using mkTx) and to check whether a given pending transaction meets the constraints (on-chain, using checkScriptContext).
~~~~~
Constructors
TxConstraints
txConstraints :: [TxConstraint]
~~~~~
data TxConstraint
Constraints on transactions that want to spend script outputs
Constructors
MustSpendAtLeast Value
MustHashDatum DatumHash Datum
~~~~~
Defining constraints
{-# INLINABLE mustHashDatum #-}
mustHashDatum :: DatumHash -> Datum -> TxConstraints i o
mustHashDatum dvh = singleton . MustHashDatum dvh

6113: <p>I'm trying to understand how <code>Constraints.mustHashDatum</code> works but I'm not able to figure out the purpose of this Constraint.</p>
<p>Any help would be great.</p>
 5788: <p>This is my beginner takeaway about Constraints.mustHashDatum after reading about TxContraints and TxConstraint and mustHashDatum at the Ledger.Constraints documentation link below.  I will also be interested in the responses so that I can know the answer too.</p>
<p>Here are my thoughts.  It seems like when we're creating a transaction, we can dictate that one of the constraints/requirements is just that there <em><strong>exist</strong></em> a Datum and a DatumHash, and that both must be supplied as part of transaction creation.  If one or both is not supplied, then the transaction won't be generated because the particular mustHashDatum constraint wouldn't be met. I think maybe the mustHashDatum constraint does this for us, since just creating that constraint requires that we provide both. Presumably, we might set this as a constraint to make sure that later code involving the transaction can use/check the Datum and the DatumHash.</p>
<p>Below are the excerpts from the documentation that seemed applicable.</p>
<p><a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-constraints/html/Ledger-Constraints.html" rel="nofollow noreferrer">https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-constraints/html/Ledger-Constraints.html</a></p>
<p>Ledger.Constraints</p>
<p>This module defines TxConstraints, a list of constraints on transactions. To construct a value of TxConstraints use the mustPayToTheScript, mustSpendAtLeast, etc functions. Once we have a TxConstraints value it can be used both to generate a transaction that satisfies the constraints (off-chain, using mkTx) and to check whether a given pending transaction meets the constraints (on-chain, using checkScriptContext).</p>
<p>~<em>~</em>~<em>~</em>~</p>
<p>Constructors</p>
<p>TxConstraints</p>
<p>txConstraints :: [TxConstraint]</p>
<p>~<em>~</em>~<em>~</em>~</p>
<p>data TxConstraint</p>
<p>Constraints on transactions that want to spend script outputs</p>
<p>Constructors</p>
<p>MustSpendAtLeast Value</p>
<p>MustHashDatum DatumHash Datum</p>
<p>~<em>~</em>~<em>~</em>~</p>
<p>Defining constraints</p>
<p>{-# INLINABLE mustHashDatum #-}</p>
<p>mustHashDatum :: DatumHash -&gt; Datum -&gt; TxConstraints i o</p>
<p>mustHashDatum dvh = singleton . MustHashDatum dvh</p>
