I'm not guru with Eff system under Haskell. What i got that method could contains the constraints for monad that should be used with.

module ChainIndexHelper

import Plutus.ChainIndex.Client
import Plutus.ChainIndex.Effects (ChainIndexQueryEffect (..))
import Control.Monad.Freer.Reader
import Control.Monad.Freer
import Control.Monad.Freer.Error

-- import Control.Monad.IO.Class
import Control.Monad.Trans

import Plutus.V1.Ledger.Scripts (DatumHash, Datum)
import Data.Function ((&))

import Network.HTTP.Client (newManager, defaultManagerSettings)

import Servant.API
import Servant.Client

testGetDatum :: DatumHash -> IO (Maybe Datum)
testGetDatum dh = do
    manager' <- newManager defaultManagerSettings
        reqDatum = DatumFromHash dh
    mbDatum <- runM
               $ runError
               $ runReader (mkClientEnv manager' (BaseUrl Http "localhost" 9083 ""))
               $ handleChainIndexClient reqDatum
    return mbDatum -- Might be post processing stmts

For scripts I have to get Datum of previous UTxO so I want to use Chain Index server and call client code. Then I'm constructing pure Cardano Tx. Signing should be on the client side.

1 Answer 1


A little dummy. Can be improved

{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE DataKinds                  #-}


runClientError :: Eff (Error ClientError ': r) a -> Eff r (Either ClientError a)
runClientError = runError

runHandleChainIndexClient :: DatumHash -> IO (Maybe Datum)
runHandleChainIndexClient dh = do
   manager' <- newManager defaultManagerSettings
      clientEnv = mkClientEnv manager' (BaseUrl Http "localhost" 9083 "")
      reqDatum = DatumFromHash dh
   mbDatum <- runM
              -- $ runError
              $ runClientError
              $ runReader clientEnv
              $ handleChainIndexClient reqDatum
   case mbDatum of
       Left _ -> return Nothing
       Right d -> return d

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.