1

My code is here.

{-# LANGUAGE DeriveAnyClass        #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE DeriveGeneric         #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators         #-}

module MarketState (
  createMarket
)where

import Plutus.Contract as Contract
import Control.Monad (void)
import Control.Applicative
import Data.Aeson (ToJSON, FromJSON)
import GHC.Generics (Generic)
import Schema (ToSchema)
import Data.String (String)
import Data.Text (Text)
import qualified PlutusTx
import Ledger (PubKeyHash(..))
import qualified Plutus.V1.Ledger.Ada as Ada
import Ledger.Constraints (TxConstraints)
import Ledger.Contexts (ScriptContext)
import Ledger.Typed.Scripts (DatumType, RedeemerType)

-- Define the market parameters
data MarketParams = MarketParams {
  event :: String,
  outcomes :: [String],
  fees :: Integer
} deriving (Generic, ToJSON, FromJSON, ToSchema)

PlutusTx.makeLift ''MarketParams

-- Define the smart contract logic
data Market = Market {
  params :: MarketParams,
  creator :: PubKeyHash
} deriving (Generic, ToJSON, FromJSON, ToSchema)

PlutusTx.makeLift ''Market

-- Create a function to deploy the smart contract
createMarket :: MarketParams -> Contract w s Text ()
createMarket params = do
  pk <- PubKeyHash <$> ownPubKey
  let market = Market params pk
  void $ submitTxConstraints (marketConstraints market) (tx market)
  logInfo $ "Market deployed at " <> show (address market)

-- Define the market constraints
marketConstraints :: Market -> TxConstraints (RedeemerType -> ScriptContext -> Bool)(DatumType, ())
marketConstraints market = mustValidateIn (to $ scriptAddress market)

-- Define the transaction logic
tx :: Market -> TxConstraints () ()
tx market = mustSpendScriptOutput (scriptTxOut $ market) (Redeemer $ PlutusTx.toBuiltinData BuyShares)
         <> mustPayToPubKey (creator market) (Ada.lovelaceValueOf $ fees $ params market)

I am a Plutus Smart Contract beginner. I don't sure how to fix this error. Please help me to fix the error.

src/MarketState.hs:58:47: error:
    • Expecting one more argument to ‘RedeemerType’
      Expected a type, but ‘RedeemerType’ has kind ‘* -> *’
    • In the first argument of ‘TxConstraints’, namely
        ‘(RedeemerType -> ScriptContext -> Bool)’
      In the type signature:
        marketConstraints :: Market
                             -> TxConstraints (RedeemerType
                                               -> ScriptContext -> Bool) (DatumType, ())
   |
58 | marketConstraints :: Market -> TxConstraints (RedeemerType -> ScriptContext -> Bool) (DatumType, ())
   |                                               ^^^^^^^^^^^^

src/MarketState.hs:58:87: error:
    • Expecting one more argument to ‘DatumType’
      Expected a type, but ‘DatumType’ has kind ‘* -> *’
    • In the second argument of ‘TxConstraints’, namely
        ‘(DatumType, ())’
      In the type signature:
        marketConstraints :: Market
                             -> TxConstraints (RedeemerType
                                               -> ScriptContext -> Bool) (DatumType, ())
   |
58 | marketConstraints :: Market -> TxConstraints (RedeemerType -> ScriptContext -> Bool) (DatumType, ())

1 Answer 1

0

RedeemerType and DatumType both require the data type to be specified, e.g. RedeemerType Integer.

If you use AllowAmbiguousTypes language extension you can do, e.g. RedeemerType a.

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.