5

I upgraded the Plutus version used by my project to: 2f11c28bd8f6d630daab582255e16d8408075bd7

PS: It is the same version Lars used in his latest lecture (Iteration #2 - Lecture #8)

Here is the code I'm using to define the endpoints:

data StarterContracts =
    MarketContract
    deriving (Eq, Ord, Show, Generic, FromJSON, ToJSON)

instance Pretty StarterContracts where
    pretty = viaShow

handleStarterContract ::
    ( Member (Error PABError) effs
    , Member (LogMsg (PABMultiAgentMsg (Builtin StarterContracts))) effs
    )
    => ContractEffect (Builtin StarterContracts)
    ~> Eff effs
handleStarterContract = handleBuiltin getSchema getContract where
    getSchema = \case
        MarketContract -> endpointsToSchemas @Market.MarketSchema
    getContract = \case
        MarketContract -> SomeBuiltin Market.endpoints

handlers :: SimulatorEffectHandlers (Builtin StarterContracts)
handlers =
    Simulator.mkSimulatorHandlers @(Builtin StarterContracts) [MarketContract]
    $ interpret handleStarterContract

And this is the error I'm getting when trying to compile it:

app/Main.hs:62:25: error:
    • Couldn't match expected type ‘(StarterContracts
                                     -> [playground-common-0.1.0.0:Playground.Types.FunctionSchema
                                           playground-common-0.1.0.0:Schema.FormSchema])
                                    -> (StarterContracts -> SomeBuiltin)
                                    -> ContractEffect (Builtin StarterContracts) x
                                    -> Eff effs x’
                  with actual type ‘Plutus.PAB.Effects.Contract.Builtin.BuiltinHandler
                                      a0’
    • The function ‘handleBuiltin’ is applied to two arguments,
      but its type ‘Plutus.PAB.Effects.Contract.Builtin.BuiltinHandler
                      a0’
      has none
      In the expression: handleBuiltin getSchema getContract
      In an equation for ‘handleStarterContract’:
          handleStarterContract
            = handleBuiltin getSchema getContract
            where
                getSchema
                  = \case MarketContract -> endpointsToSchemas @MarketSchema
                getContract = \case MarketContract -> SomeBuiltin endpoints
    • Relevant bindings include
        handleStarterContract :: ContractEffect (Builtin StarterContracts)
                                 ~> Eff effs
          (bound at app/Main.hs:62:1)
   |
62 | handleStarterContract = handleBuiltin getSchema getContract where
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

app/Main.hs:70:5: error:
    • Couldn't match type ‘Simulator.SimulatorContractHandler
                             (Builtin StarterContracts)
                           -> SimulatorEffectHandlers (Builtin StarterContracts)’
                     with ‘Plutus.PAB.Core.EffectHandlers
                             (Builtin StarterContracts)
                             (Simulator.SimulatorState (Builtin StarterContracts))’
      Expected type: SimulatorEffectHandlers (Builtin StarterContracts)
        Actual type: Simulator.SimulatorContractHandler
                       (Builtin StarterContracts)
                     -> SimulatorEffectHandlers (Builtin StarterContracts)
    • In the expression:
        Simulator.mkSimulatorHandlers
          @(Builtin StarterContracts) [MarketContract]
          $ interpret handleStarterContract
      In an equation for ‘handlers’:
          handlers
            = Simulator.mkSimulatorHandlers
                @(Builtin StarterContracts) [MarketContract]
                $ interpret handleStarterContract
   |
70 |     Simulator.mkSimulatorHandlers @(Builtin StarterContracts) [MarketContract]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

app/Main.hs:70:63: error:
    • Couldn't match expected type ‘Ledger.Fee.FeeConfig’
                  with actual type ‘[StarterContracts]’
    • In the second argument of ‘Simulator.mkSimulatorHandlers’, namely
        ‘[MarketContract]’
      In the expression:
        Simulator.mkSimulatorHandlers
          @(Builtin StarterContracts) [MarketContract]
      In the expression:
        Simulator.mkSimulatorHandlers
          @(Builtin StarterContracts) [MarketContract]
          $ interpret handleStarterContract
   |
70 |     Simulator.mkSimulatorHandlers @(Builtin StarterContracts) [MarketContract]
   |                                                               ^^^^^^^^^^^^^^^^

app/Main.hs:71:7: error:
    • Couldn't match expected type ‘Ledger.TimeSlot.SlotConfig’
                  with actual type ‘Eff
                                      (ContractEffect (Builtin StarterContracts) : effs0) x0
                                    -> Eff effs0 x0’
    • Probable cause: ‘interpret’ is applied to too few arguments
      In the second argument of ‘($)’, namely
        ‘interpret handleStarterContract’
      In the expression:
        Simulator.mkSimulatorHandlers
          @(Builtin StarterContracts) [MarketContract]
          $ interpret handleStarterContract
      In an equation for ‘handlers’:
          handlers
            = Simulator.mkSimulatorHandlers
                @(Builtin StarterContracts) [MarketContract]
                $ interpret handleStarterContract
   |
71 |     $ interpret handleStarterContract
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 Answer 1

3

Plutus is still in active development, so changes in the API can occur every week.

For your case, go look at a similar example in the PAB.

In your specific case, you'll need to change your handlers function to :

handlers :: SimulatorEffectHandlers (Builtin StarterContracts)
handlers =
    Simulator.mkSimulatorHandlers def def 
    $ interpret (contractHandler Builtin.handleBuiltin)

Then you'll need to implement the HasDefinitions and the HasPSTypes typeclasses for your StarterContracts. For the HasPSTypes, you can just use the default implementation which is:

instance HasPSTypes StarterContracts where
    psTypes _ = []

Hope that helps.

1
  • 1
    Yes, this is very helpful, thank you! I also got another error after applying the new changes. it was about def not being defined anywhere, I fixed it by adding the following import statement: import Data.Default (Default (..)) Commented Aug 24, 2021 at 11:22

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.