0

Im trying to create and send a utxo of tokens to a wallet through collectFromScript and I cant seem to get it to work. Can I get some help? I am trying to create a valid input for the collectFromScript function but I dont know how to map TxOutRef and ChainIndexTxOut so that it will produce (Map TxoutRef ChainIndexTxOut).

purchaseUtxo ::  ChainIndexTxOut
purchaseUtxo = case fromTxOut (scriptTxOut (Value.singleton (policyID contractInfo) (nameOfToken contractInfo) (1)) validate (Datum $ PlutusTx.toBuiltinData ()) )  of
    Nothing     ->  error ()
    Just x      ->  x

purchase :: AsContractError e => PurchaseParams -> Contract w s e ()
purchase p =  do
    utxos <- utxosAt valAddress
    utxoMap <- (map TxOutRef (purchaseUtxo))
    let redeemer = ()
        pkh = ownPubKey
        tx       = Constraints.mustPayToTheScript () price <> collectFromScript utxoMap
        
    void (submitTxConstraintsSpending lootBox utxos tx)









Compilation Error, Line 146, Column 17 (jump)

 error:
    • Couldn't match expected type ‘Contract
                                      w s e (Data.Map.Internal.Map TxOutRef ChainIndexTxOut)’
                  with actual type ‘[Integer] -> [TxOutRef]’
    • Probable cause: ‘map’ is applied to too few arguments
      In a stmt of a 'do' block: utxoMap <- (map (TxOutRef purchaseUtxo))
      In the expression:
        do utxos <- utxosAt valAddress
           utxoMap <- (map (TxOutRef purchaseUtxo))
           let redeemer = ()
               pkh = ownPubKey
               ....
           void (submitTxConstraintsSpending lootBox utxos tx)
      In an equation for ‘purchase’:
          purchase p
            = do utxos <- utxosAt valAddress
                 utxoMap <- (map (TxOutRef purchaseUtxo))
                 let redeemer = ...
                     ....
                 ....
    • Relevant bindings include
        purchase :: PurchaseParams -> Contract w s e ()
          (bound at /tmp/web-ghc-work-689a3b2c3d276385/Main.hs:144:1)
    |
146 |     utxoMap <- (map (TxOutRef purchaseUtxo))
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Compilation Error, Line 146, Column 31 (jump)

 error:
    • Couldn't match expected type ‘TxId’
                  with actual type ‘ChainIndexTxOut’
    • In the first argument of ‘TxOutRef’, namely ‘purchaseUtxo’
      In the first argument of ‘map’, namely ‘(TxOutRef purchaseUtxo)’
      In a stmt of a 'do' block: utxoMap <- (map (TxOutRef purchaseUtxo))
    |
146 |     utxoMap <- (map (TxOutRef purchaseUtxo))
    |           

                ^^^^^^^^^^^^
2
  • It might be more valuable to the site if you pose your question in a way other people can find it. Commented Jan 27, 2022 at 0:09
  • I changed my explanation I how that it helps
    – Floof99
    Commented Jan 27, 2022 at 1:26

1 Answer 1

1
    • Couldn't match expected type ‘Contract
                                      w s e (Data.Map.Internal.Map TxOutRef ChainIndexTxOut)’
                  with actual type ‘[Integer] -> [TxOutRef]’
    • Probable cause: ‘map’ is applied to too few arguments

This is saying that it expects a Contract monad but it's getting a function [Integer] -> [TxOutRef]. So, there are two problems:

You aren't passing map any [integer], so it's just an unresolved function, but, more importantly,map doesn't return a Contract monad, so <- doesn't make sense here. <- within a do block must be used on the same type of monad, which in this case is Contract.

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.