user4129: 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))
    |           

                ^^^^^^^^^^^^


user1130:     • 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.

4129: <p>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).</p>
<pre><code>purchaseUtxo ::  ChainIndexTxOut
purchaseUtxo = case fromTxOut (scriptTxOut (Value.singleton (policyID contractInfo) (nameOfToken contractInfo) (1)) validate (Datum $ PlutusTx.toBuiltinData ()) )  of
    Nothing     -&gt;  error ()
    Just x      -&gt;  x

purchase :: AsContractError e =&gt; PurchaseParams -&gt; Contract w s e ()
purchase p =  do
    utxos &lt;- utxosAt valAddress
    utxoMap &lt;- (map TxOutRef (purchaseUtxo))
    let redeemer = ()
        pkh = ownPubKey
        tx       = Constraints.mustPayToTheScript () price &lt;&gt; 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] -&gt; [TxOutRef]’
    • Probable cause: ‘map’ is applied to too few arguments
      In a stmt of a 'do' block: utxoMap &lt;- (map (TxOutRef purchaseUtxo))
      In the expression:
        do utxos &lt;- utxosAt valAddress
           utxoMap &lt;- (map (TxOutRef purchaseUtxo))
           let redeemer = ()
               pkh = ownPubKey
               ....
           void (submitTxConstraintsSpending lootBox utxos tx)
      In an equation for ‘purchase’:
          purchase p
            = do utxos &lt;- utxosAt valAddress
                 utxoMap &lt;- (map (TxOutRef purchaseUtxo))
                 let redeemer = ...
                     ....
                 ....
    • Relevant bindings include
        purchase :: PurchaseParams -&gt; Contract w s e ()
          (bound at /tmp/web-ghc-work-689a3b2c3d276385/Main.hs:144:1)
    |
146 |     utxoMap &lt;- (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 &lt;- (map (TxOutRef purchaseUtxo))
    |
146 |     utxoMap &lt;- (map (TxOutRef purchaseUtxo))
    |           

                ^^^^^^^^^^^^
</code></pre>
 1130: <pre><code>    • Couldn't match expected type ‘Contract
                                      w s e (Data.Map.Internal.Map TxOutRef ChainIndexTxOut)’
                  with actual type ‘[Integer] -&gt; [TxOutRef]’
    • Probable cause: ‘map’ is applied to too few arguments
</code></pre>
<p>This is saying that it expects a <code>Contract</code> monad but it's getting a function <code>[Integer] -&gt; [TxOutRef]</code>. So, there are two problems:</p>
<p>You aren't passing <code>map</code> any <code>[integer]</code>, so it's just an unresolved function, but, more importantly,<code>map</code> doesn't return a <code>Contract</code> monad, so <code>&lt;-</code> doesn't make sense here. <code>&lt;-</code> within a <code>do</code> block must be used on the same type of monad, which in this case is <code>Contract</code>.</p>
