3

I am new to haskell and I am trying to run a few expressions from the English Auction Contract in the repl.

So if I want to run ValidatorHash "f" from the second last line of the Contract in week01, how do I do it in the repl here [nix-shell:~/plutus-pioneer-program/code/week01]$ cabal repl?

What I tried

> import Ledger.ValidatorHash
> Ledger.ValidatorHash "f"
error: Couldn't match expected type ‘PlutusTx.Builtins.Internal.BuiltinByteString’
                  with actual type ‘[Char]’

then

> import PlutusTx.Builtins.Internal
> Ledger.ValidatorHash (BuiltinByteString "f")
error: Couldn't match expected type ‘bytestring-0.10.12.0:Data.ByteString.Internal.ByteString’
                  with actual type ‘[Char]’

then

> import Data.ByString as BS
error: Could not find module ‘Data.ByString’
    Perhaps you meant
      Data.ByteString (needs flag -package-key bytestring-0.10.12.0)
      Data.String (from base-4.14.1.0)

So do I really need to close this repl and figure out the way to open the repl with the flag? Or is there something very obvious that I am missing?


Edit #1: added non-typo error for bytestring

> import Data.ByteString as BS
error: Could not load module ‘Data.ByteString’
    It is a member of the hidden package ‘bytestring-0.10.12.0’.
    Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.

Looks like bytestring is hidden. Is it still possible to run ValidatorHash "f" using any other means?


Edit #2

My question was initially specific to find out the origin of 66 when using the token in week01 code as ValidatorHash "f" is taken from this statement in the contract myToken = KnownCurrency (ValidatorHash "f") "Token" (TokenName "T" :| []). But I was unable to evaluate it.

3 Answers 3

1

Somewhere you have a typo. "ByString" should be "ByteString".

1
  • thanks, I changed my final question to address it.
    – Roofi
    Commented Jan 14, 2022 at 9:10
1

It was newbie mistake. There are these lines at the top

{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveAnyClass             #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE TypeOperators              #-}

I ran the following in the repl

:set -XDataKinds
:set -XDeriveAnyClass
:set -XDeriveGeneric
:set -XDerivingStrategies
:set -XFlexibleContexts
:set -XGeneralizedNewtypeDeriving
:set -XLambdaCase
:set -XMultiParamTypeClasses
:set -XNoImplicitPrelude
:set -XOverloadedStrings
:set -XRecordWildCards
:set -XScopedTypeVariables
:set -XTemplateHaskell
:set -XTypeApplications
:set -XTypeFamilies
:set -XTypeOperators

and then simply evaluated the expression and it worked!

> Ledger.ValidatorHash "f"
66
0

Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.

Do you have a cabal file somewhere? If so, you need to add the bytestring package.

1
  • Instead of making bytestring work, can I just evaluate ValidatorHash "f"? Or do I need to setup some flags (like maybe :set -XTemplateHaskell)? I was successfully able to compile week01 so I was trying to run this expression in the repl.
    – Roofi
    Commented Jan 14, 2022 at 9:48

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.