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))
|
^^^^^^^^^^^^