I give to Integer via an endpoint function, multiply them and give them to Constraints.mustPayToTheScript. For this I need the result to be converted into an Value. Does Anyone know how to do this?

 buy =  endpoint @"buy" @BuyParams $ \ (BuyParams fst scd ) -> do
    let amt = fst*scd
    let tx         = Constraints.mustPayToTheScript (hashString fst) amt
    void (submitTxConstraints gameInstance tx)
  • Is ADA what you want to pay to the script?
    – kindofdev
    Feb 25, 2022 at 12:47

1 Answer 1


Supposing that you want to pay ADA to the script, you can use lovelaceValueOf :: Integer -> Value from Plutus.V1.Ledger.Ada as follows:

import qualified Plutus.V1.Ledger.Ada as Ada

buy = endpoint @"buy" @BuyParams $ \ (BuyParams fst scd ) -> do
   let amt = fst*scd
       val = Ada.lovelaceValueOf amt
       tx  = Constraints.mustPayToTheScript (hashString fst) val
   void (submitTxConstraints gameInstance tx)

enter image description here

Hope this will be useful.

  • Yes! Solved it thanks :)
    – John_Bones
    Feb 26, 2022 at 13:32
  • @John_Bones more than welcome!
    – kindofdev
    Feb 26, 2022 at 14:51

Your Answer

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

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