2

What I can figure out:

mustSpendAtLeast is basically just a wrapper around MustSpendAtLeast. This gets processed here, by adding a required value to this thing. These values get turned into outputs in addMissingValueSpent.

With all this, I still don't understand how this constraint is supposed to be used.

edit: The root of my inability to figure this out was that I was looking in the wrong place for the information. Ledger.Constraints.OnChain is the place to go to figure out what all the constraints actually mean. In the case of mustSpendAtLeast, it simply means that all the values of all the inputs to the transaction must add up to at least that amount.

1 Answer 1

2

Here is a contrived use case:

Imagine some dApp that includes governance (voting and stuff). Among the requirements for voting on some referendum, you must prove your right to vote with governance tokens. The smart contract doesn't need to be paid the governance tokens, rather just see that they are included in any vote transaction, after which the tokens can be returned to the voter.

To achieve this, you will need to spend the tokens, and just have yourself as the recipient*. You will include the constraint:

Constraints.mustSpendAtLeast govTokenValue

Which under the hood will select enough UTxOs to spend and meet the minimum govTokenValue (or return an error if you don't have enough).

The dApp smart contract can then check its ScriptContext to ensure that at least the minimum number of governance tokens needed were included in the transaction to perform the desired action, e.g. vote.

*not specifying a recipient will default to returning them to the transaction builder (you)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.