<h1><code>tokenName</code> is not meant to be used on-chain</h1>
<p><a href="https://github.com/input-output-hk/plutus-apps/issues/498" rel="nofollow noreferrer">see this closed issue</a></p>
<p>due to the fact of <code>:t tokenName</code> being <code>ByteString -&gt; TokenName</code> ( and not <code>BuiltinByteString -&gt; TokenName</code>) the correct way to build dynamically a <code>TokenName</code> is by using the <code>TokenName</code> constructor itself (and NOT the helper function)</p>

CC BY-SA 4.0
2022-06-07T16:44:31.953Z
2022-06-07T16:44:31.953Z
Michele Nuzzi
<p>I'm not sure is relevant but the code in question is for a generic Validator (with Datums and Redeemers) used to get a forwarded minting policy</p>
<p>the problem should be clear from the title, I can't get to construct a <code>TokenName</code> value starting form a ``ByteString```</p>
<p>I assume the rror is dued to the <code>plutus-tx-plugin</code> library so all the <code>ghc-options</code> specified in the <a href="https://playground.plutus.iohkdev.io/doc/plutus/troubleshooting.html#plugin-errors" rel="nofollow noreferrer">troubleshooting section for the Plutus documentation</a> are enabled (without much success)</p>
<p>the error I get is the following</p>
<pre><code>GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char#
Context: Compiling type: GHC.Prim.Char#
Context: Compiling data constructor type: GHC.Types.C#
Context: Compiling type: GHC.Types.Char
Context: Compiling type: GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$ @ GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$
                           @ GHC.Base.String @ Plutus.V1.Ledger.Value.TokenName
Context: Compiling expr: PlutusTx.Base.$
                           @ GHC.Base.String
                           @ Plutus.V1.Ledger.Value.TokenName
                           (PlutusTx.Base..
                              @ Data.ByteString.Internal.ByteString
                              @ Plutus.V1.Ledger.Value.TokenName
                              @ GHC.Base.String
                              Plutus.V1.Ledger.Value.tokenName
                              Data.ByteString.Char8.pack) 
</code></pre>
<p>and keeps expanding for a while...</p>
<p>I know for sure (by commenting out) the code causing this is the following:</p>
<blockquote>
<p><strong><em>NOTE:</em></strong> I've commented out everything related to <code>collectionCurrencySymbol</code> from the moment that is causing problems too and I'll likely change it, any idea is welcome but is not the main point of the question</p>
</blockquote>
<pre><code> expectedTokenName :: Value.TokenName
 expectedTokenName =  Value.tokenName $ &quot;My Awesome NFT collection #&quot; &lt;&gt; integerToBS8 datumCounter

 -- collectionCurrencySymbol :: Value.CurrencySymbol
 -- collectionCurrencySymbol = (Value.mpsSymbol . Ledger.mintingPolicyHash . mkForwardingMintingPolicy ) (Ctx.ownHash ctx)

singleTokenMinted :: PTxP.Bool
singleTokenMinted =
  case Value.flattenValue (txInfoMint ( Ctx.scriptContextTxInfo ctx) ) of
    [( mintedCurrencySym , mintedTokenName , mintedAmount )] -&gt;
      -- mintedCurrencySym == collectionCurrencySymbol   PTxP.&amp;&amp;
      mintedTokenName   == expectedTokenName          PTxP.&amp;&amp;
      mintedAmount      == 1
    _                                                        -&gt;
      traceError &quot;minting more than 1 AssetClass&quot;
</code></pre>
<p>where <code>integerToBS8</code> is as simple as :</p>
<pre><code>{-# INLINEABLE integerToBS8 #-}
integerToBS8 :: Integer -&gt; BS8.ByteString
integerToBS8 int
    | int == 0 = BS8.pack &quot;0&quot;
    | int == 1 = BS8.pack &quot;1&quot;
    | int == 2 = BS8.pack &quot;2&quot;
    | int == 3 = BS8.pack &quot;3&quot;
    | int == 4 = BS8.pack &quot;4&quot;
    | int == 5 = BS8.pack &quot;5&quot;
    | int == 6 = BS8.pack &quot;6&quot;
    | int == 7 = BS8.pack &quot;7&quot;
    | int == 8 = BS8.pack &quot;8&quot;
    | int == 9 = BS8.pack &quot;9&quot;
    | otherwise = integerToBS8 ( int `div` 10 ) &lt;&gt; integerToBS8 ( int `mod` 10 )
</code></pre>
<p>some conventions I use</p>
<pre><code>import qualified Data.ByteString.Char8       as BS8
import qualified Ledger.Contexts as Ctx
import qualified Ledger.Value as Value
import qualified Ledger
import PlutusTx.Prelude as PTxP
</code></pre>
<p>It seems to me <code>GHC</code> just doesn't like raw strings (since <code>OverloadedStrings</code> is just adding silently a bunch of <code>pack</code> form the <code>IsString</code> typeclass where needed)</p>
<p>any idea on what's wrong?</p>

<plutus><plutus-pioneer-program><smart-contract><nft><haskell>
Can't create ```TokenName``` using ```tokenName``` with error ```GHC Core to PLC plugin: E042:Error: Unsupported feature: ...```
# Can't create ```TokenName``` using ```tokenName``` with error ```GHC Core to PLC plugin: E042:Error: Unsupported feature: ...```

(Asked by: username_0 on 2022-06-04)

I'm not sure is relevant but the code in question is for a generic Validator (with Datums and Redeemers) used to get a forwarded minting policy
the problem should be clear from the title, I can't get to construct a TokenName value starting form a ``ByteString```
I assume the rror is dued to the plutus-tx-plugin library so all the ghc-options specified in the troubleshooting section for the Plutus documentation are enabled (without much success)
the error I get is the following
GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char#
Context: Compiling type: GHC.Prim.Char#
Context: Compiling data constructor type: GHC.Types.C#
Context: Compiling type: GHC.Types.Char
Context: Compiling type: GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$ @ GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$
                           @ GHC.Base.String @ Plutus.V1.Ledger.Value.TokenName
Context: Compiling expr: PlutusTx.Base.$
                           @ GHC.Base.String
                           @ Plutus.V1.Ledger.Value.TokenName
                           (PlutusTx.Base..
                              @ Data.ByteString.Internal.ByteString
                              @ Plutus.V1.Ledger.Value.TokenName
                              @ GHC.Base.String
                              Plutus.V1.Ledger.Value.tokenName
                              Data.ByteString.Char8.pack) 

and keeps expanding for a while...
I know for sure (by commenting out) the code causing this is the following:

NOTE: I've commented out everything related to collectionCurrencySymbol from the moment that is causing problems too and I'll likely change it, any idea is welcome but is not the main point of the question

 expectedTokenName :: Value.TokenName
 expectedTokenName =  Value.tokenName $ "My Awesome NFT collection #" <> integerToBS8 datumCounter

 -- collectionCurrencySymbol :: Value.CurrencySymbol
 -- collectionCurrencySymbol = (Value.mpsSymbol . Ledger.mintingPolicyHash . mkForwardingMintingPolicy ) (Ctx.ownHash ctx)

singleTokenMinted :: PTxP.Bool
singleTokenMinted =
  case Value.flattenValue (txInfoMint ( Ctx.scriptContextTxInfo ctx) ) of
    [( mintedCurrencySym , mintedTokenName , mintedAmount )] ->
      -- mintedCurrencySym == collectionCurrencySymbol   PTxP.&&
      mintedTokenName   == expectedTokenName          PTxP.&&
      mintedAmount      == 1
    _                                                        ->
      traceError "minting more than 1 AssetClass"

where integerToBS8 is as simple as :
{-# INLINEABLE integerToBS8 #-}
integerToBS8 :: Integer -> BS8.ByteString
integerToBS8 int
    | int == 0 = BS8.pack "0"
    | int == 1 = BS8.pack "1"
    | int == 2 = BS8.pack "2"
    | int == 3 = BS8.pack "3"
    | int == 4 = BS8.pack "4"
    | int == 5 = BS8.pack "5"
    | int == 6 = BS8.pack "6"
    | int == 7 = BS8.pack "7"
    | int == 8 = BS8.pack "8"
    | int == 9 = BS8.pack "9"
    | otherwise = integerToBS8 ( int `div` 10 ) <> integerToBS8 ( int `mod` 10 )

some conventions I use
import qualified Data.ByteString.Char8       as BS8
import qualified Ledger.Contexts as Ctx
import qualified Ledger.Value as Value
import qualified Ledger
import PlutusTx.Prelude as PTxP

It seems to me GHC just doesn't like raw strings (since OverloadedStrings is just adding silently a bunch of pack form the IsString typeclass where needed)
any idea on what's wrong?

**Tags:** plutus, plutus-pioneer-program, smart-contract, nft, haskell

---

## 1 answers

### Answer by username_0 on 2022-06-07. Score: 0 | Accepted answer

# `tokenName` is not meant to be used on-chain

[see this closed issue](https://github.com/input-output-hk/plutus-apps/issues/498)

due to the fact of `:t tokenName` being `ByteString -> TokenName` ( and not `BuiltinByteString -> TokenName`) the correct way to build dynamically a `TokenName` is by using the `TokenName` constructor itself (and NOT the helper function)


---

