<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>

CC BY-SA 4.0
2022-01-22T11:07:30.320Z
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Community
CC BY-SA 4.0
2022-01-22T04:54:49.533Z
2022-01-22T05:17:35.267Z
2022-01-22T05:17:35.267Z
phendi
<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>

<plutus><datum>
How does Constraints.mustHashDatum work?
# How does Constraints.mustHashDatum work?

(Asked by: username_0 on 2022-01-21)

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.

**Tags:** plutus, datum

---

## 1 answers

### Answer by username_1 on 2022-01-22. Score: 1

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

> **Comments:**
> **username_2**: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  

---

