<p>For some reason checking for equality with the <code>TokenName</code> type isn't possible on-chain (at least that's my theory, maybe <code>TokenName</code> 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.</p>
<p>So you would have</p>
<pre><code>{-# INLINABLE ivyToken #-}
ivyToken :: BuiltinByteString
ivyToken = &quot;IVY_T1&quot;
</code></pre>
<p>Where <code>BuiltinByteString</code> is imported from <code>PlutusTx.Prelude</code></p>
<pre><code>checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
    [(cs, (TokenName tn'), amt)] -&gt; cs  == ownCurrencySymbol ctx &amp;&amp; tn' == ivyToken &amp;&amp; amt == initialAmount
    _                -&gt; False
</code></pre>

CC BY-SA 4.0
2022-01-21T14:34:16.513Z
2022-01-21T14:34:16.513Z
Mateus
<p>I tried compiling a solution from the examples provided in PPP Iteration #2 but got stuck. Any ideas?</p>
<p><strong>Code:</strong> <a href="https://github.com/ILIYANGERMANOV/cardano-smart-contracts/blob/main/ivy-token/src/MintIvy.hs" rel="nofollow noreferrer">https://github.com/ILIYANGERMANOV/cardano-smart-contracts/blob/main/ivy-token/src/MintIvy.hs</a></p>
<p><strong>Error:</strong></p>
<pre><code>...
Plutus.V1.Ledger.Value.TokenName&gt;_N)) ; PlutusTx.Eq.N:Eq[0]
                                                                                                                                                             &lt;Plutus.V1.Ledger.Value.TokenName&gt;_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])
                                                                                 -&gt;_R Sym (Plutus.V1.Ledger.Value.N:TokenName[0])
                                                                                 -&gt;_R &lt;GHC.Types.Bool&gt;_R) ; Sym (PlutusTx.Eq.N:Eq[0]
                                                                                                                     &lt;Plutus.V1.Ledger.Value.TokenName&gt;_N)) ; PlutusTx.Eq.N:Eq[0]
                                                                                                                                                                  &lt;Plutus.V1.Ledger.Value.TokenName&gt;_N)))
                                                                :: GHC.Types.Coercible
                                                                     Plutus.V1.Ledger.Value.TokenName
                                                                     PlutusTx.Builtins.Internal.BuiltinByteString))
                                                of {
                                                  GHC.Types.False -&gt; GHC.Types.False;
                                                  GHC.Types.True -&gt;
                                                    PlutusTx.Builtins.Internal.ifThenElse
                                                      @ GHC.Types.Bool
                                                      (PlutusTx.Builtins.Internal.equalsInteger
                                                         amt MintIvy.initialAmount)
                                                      GHC.Types.True
                                                      GHC.Types.False
                                                }
                                            };
                                          : _ [Occ=Dead] _ [Occ=Dead] -&gt; GHC.Types.False
                                        }
                                        }
                                    }
                               of {
                                 GHC.Types.False -&gt;
                                   PlutusTx.Builtins.Internal.trace
                                     @ GHC.Types.Bool
                                     (GHC.Magic.noinline
                                        @ (GHC.Base.String -&gt; PlutusTx.Builtins.Internal.BuiltinString)
                                        PlutusTx.Builtins.Class.stringToBuiltinString
                                        (GHC.CString.unpackCString# &quot;wrong amount minted&quot;#))
                                     GHC.Types.False;
                                 GHC.Types.True -&gt; GHC.Types.True
                               }
                           }
                           }
                           }
**Context: Compiling definition of: MintIvy.mkPolicy
Context: Compiling expr: MintIvy.mkPolicy
Context: Compiling expr: PlutusTx.Base..
                           @ (() -&gt; Plutus.V1.Ledger.Contexts.ScriptContext -&gt; 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 &quot;ivy-token-0.1.0.0-inplace:MintIvy:(93,8)-(93,69)&quot;**
`
</code></pre>

CC BY-SA 4.0
2022-01-22T11:28:19.293Z
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
Community
<plutus><plutus-pioneer-program><minting><plutustx>
Cannot compile parameterized mintingPolicy to Plutus
# Cannot compile parameterized mintingPolicy to Plutus

(Asked by: username_0 on 2022-01-20)

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]
                                                                                                                                                             _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 _R) ; Sym (PlutusTx.Eq.N:Eq[0]
                                                                                                                     _N)) ; PlutusTx.Eq.N:Eq[0]
                                                                                                                                                                  _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)"**
`

**Tags:** plutus, plutus-pioneer-program, minting, plutustx
> **Comments:**
> **username_1**: Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.  

---

## 1 answers

### Answer by username_2 on 2022-01-21. Score: 0 | Accepted answer

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


---

