1

I tried compiling a solution from the examples provided in PPP Iteration #2 but got stuck. Any ideas?

Code: https://github.com/ILIYANGERMANOV/cardano-smart-contracts/blob/main/ivy-token/src/MintIvy.hs

Error:

...
Plutus.V1.Ledger.Value.TokenName>_N)) ; PlutusTx.Eq.N:Eq[0]
                                                                                                                                                             <Plutus.V1.Ledger.Value.TokenName>_N))
                                                                :: GHC.Types.Coercible
                                                                     Plutus.V1.Ledger.Value.TokenName
                                                                     PlutusTx.Builtins.Internal.BuiltinByteString))
                                                       (MintIvy.ivyToken
                                                        `cast` (Sym (Nth:2
                                                                         (Nth:3
                                                                              (((Sym (Plutus.V1.Ledger.Value.N:TokenName[0])
                                                                                 ->_R Sym (Plutus.V1.Ledger.Value.N:TokenName[0])
                                                                                 ->_R <GHC.Types.Bool>_R) ; Sym (PlutusTx.Eq.N:Eq[0]
                                                                                                                     <Plutus.V1.Ledger.Value.TokenName>_N)) ; PlutusTx.Eq.N:Eq[0]
                                                                                                                                                                  <Plutus.V1.Ledger.Value.TokenName>_N)))
                                                                :: GHC.Types.Coercible
                                                                     Plutus.V1.Ledger.Value.TokenName
                                                                     PlutusTx.Builtins.Internal.BuiltinByteString))
                                                of {
                                                  GHC.Types.False -> GHC.Types.False;
                                                  GHC.Types.True ->
                                                    PlutusTx.Builtins.Internal.ifThenElse
                                                      @ GHC.Types.Bool
                                                      (PlutusTx.Builtins.Internal.equalsInteger
                                                         amt MintIvy.initialAmount)
                                                      GHC.Types.True
                                                      GHC.Types.False
                                                }
                                            };
                                          : _ [Occ=Dead] _ [Occ=Dead] -> GHC.Types.False
                                        }
                                        }
                                    }
                               of {
                                 GHC.Types.False ->
                                   PlutusTx.Builtins.Internal.trace
                                     @ GHC.Types.Bool
                                     (GHC.Magic.noinline
                                        @ (GHC.Base.String -> PlutusTx.Builtins.Internal.BuiltinString)
                                        PlutusTx.Builtins.Class.stringToBuiltinString
                                        (GHC.CString.unpackCString# "wrong amount minted"#))
                                     GHC.Types.False;
                                 GHC.Types.True -> GHC.Types.True
                               }
                           }
                           }
                           }
**Context: Compiling definition of: MintIvy.mkPolicy
Context: Compiling expr: MintIvy.mkPolicy
Context: Compiling expr: PlutusTx.Base..
                           @ (() -> Plutus.V1.Ledger.Contexts.ScriptContext -> GHC.Types.Bool)
                           @ Ledger.Typed.Scripts.MonetaryPolicies.WrappedMintingPolicyType
                           @ MintIvy.MintingIvyParam
                           (Ledger.Typed.Scripts.MonetaryPolicies.wrapMintingPolicy
                              @ () PlutusTx.IsData.Instances.$fUnsafeFromData())
                           MintIvy.mkPolicy
Context: Compiling expr at "ivy-token-0.1.0.0-inplace:MintIvy:(93,8)-(93,69)"**
`
1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Jan 22 at 11:28

1 Answer 1

0

For some reason checking for equality with the TokenName type isn't possible on-chain (at least that's my theory, maybe TokenName itself is not acceptable). Still, you can define your token as a builtin byte string and then compare that to the token name using pattern mathcing.

So you would have

{-# INLINABLE ivyToken #-}
ivyToken :: BuiltinByteString
ivyToken = "IVY_T1"

Where BuiltinByteString is imported from PlutusTx.Prelude

checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
    [(cs, (TokenName tn'), amt)] -> cs  == ownCurrencySymbol ctx && tn' == ivyToken && amt == initialAmount
    _                -> False

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.