2

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)
1
  • Is ADA what you want to pay to the script?
    – kindofdev
    Commented Feb 25, 2022 at 12:47

1 Answer 1

2

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.

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

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.