<p>Yes. Using ghci in Plutus repo I'll show you how. I will use fully qualified functions for clarity, and don't forget to <code>:set -XOverloadedStrings</code>.</p>
<p>Plutus observes all tokens in an output using txOutValue of <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Api.html#t:TxOut" rel="nofollow noreferrer">TxOut</a>. To define our own <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Api.html#t:Value" rel="nofollow noreferrer">Value</a> we can do (taken from <a href="https://youtu.be/SsaVjSsPPcg?t=491" rel="nofollow noreferrer">PPP Lecture#5</a>):</p>
<pre><code>&gt; let v = Plutus.V1.Ledger.Value.singleton &quot;a8ff&quot; &quot;ABC&quot; 7 &lt;&gt; Plutus.V1.Ledger.Ada.lovelaceValueOf 42 &lt;&gt; Plutus.V1.Ledger.Value.singleton &quot;a8ff&quot; &quot;XYZ&quot; 100
&gt; v
Value (Map [(,Map [(&quot;&quot;,42)]),(a8ff,Map [(&quot;ABC&quot;,7),(&quot;XYZ&quot;,100)])])
</code></pre>
<p>To filter by <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Value.html#v:currencySymbol" rel="nofollow noreferrer">CurrencySymbol</a> we can do:</p>
<pre><code>&gt; PlutusTx.AssocMap.keys $ Data.Maybe.fromJust $ PlutusTx.AssocMap.lookup &quot;a8ff&quot; (Plutus.V1.Ledger.Value.getValue v)
[&quot;ABC&quot;,&quot;XYZ&quot;]
</code></pre>
<p>This gives you <code>TokenName</code>s for <code>CurrencySymbol</code> a8ff. Ada's <code>CurrencySymbol</code> of <code>&quot;&quot;</code> has been filtered out.</p>

CC BY-SA 4.0
2022-01-24T12:30:31.133Z
2022-01-24T12:30:31.133Z
james
<p>You cannot have multiple TokenNames belonging to the same CurrencySymbol. Together, TokenName &amp; CurrencySymbol can form an asset class. Once this asset class is formed, it can be wrapped in a Value list.</p>
<p>The reason that TokenName &amp; CurrencySymbol must be 1-1 is that the CurrencySymbol is the hash of the monitary policy script used to validate the Token.</p>
<p>If you had multiple tokens with different TokenNames using the same CurrencySymbol, they would all use the same monitary policy, and that would create some issues with validation.</p>

CC BY-SA 4.0
2021-06-23T09:53:08.503Z
@Aoaddeola, you can edit and delete your own comments ;-)
gRebel
CC BY-SA 4.0
2021-06-23T12:33:43.730Z
Thanks @gRebel :)
Aoaddeola
CC BY-SA 4.0
2021-06-23T12:33:56.100Z
According to lecture #5 of the PPP, Lars demonstrated on the command line how to combine tokens using the Value.singleton function... `singleton "a8ff" "ABC" 7 <> lovelaceValueOf 42 <> singleton "a8ff" "XYZ" 100` thereby producing: `Value (Map [(,Map [("",42)]),(a8ff,Map [("ABC",7),("XYZ",100)])])`... Hence, I fail to see how multiple TokenNames can't map to a single CurrencySymbol/Monetary Policy.
Aoaddeola
CC BY-SA 4.0
2021-06-24T12:50:25.983Z
Mmmm I see the confusion. Value is simply a container for a token or multiple tokens of different types(as shown above). It is different from the CurrencySymbol. In the above example, each one of these singleton tokens have their own TokenName and  CurrencySymbol. They are then grouped using the <> operator into a Value.
Isaac Padberg
CC BY-SA 4.0
2021-07-01T11:48:01.810Z
Yes, you are correct in your explanation. But the fact remains that both `TokenName`s "XYZ" and "ABC" belong to the same `CurrencySymbol` "a8ff"
Aoaddeola
CC BY-SA 4.0
2021-07-01T18:03:35.213Z
The same name is used by Lars because he was being slightly lazy here. When the singleton function is used on the blockchain, there will be a check to ensure that the Currency Symbol does not already exist. In the example above its okay to have the same CurrencySymbol because these functions are not being executed on the blockchain.
Isaac Padberg
CC BY-SA 4.0
2021-07-09T14:04:00.847Z
I'd like you to demonstrate what you mean by "there will be a check to ensure that the Currency Symbol does not already exist". You can find me on discord with same user account (aoaddeola) :)
Aoaddeola
CC BY-SA 4.0
2021-08-31T01:50:15.177Z
This is an incorrect answer: there is not a 1-1 relationship between CurrencySymbol and TokenName, in fact on the contrary one can have an arbitrary number of tokens ( TokenName ) operating within the same CurrencySymbol (policy).
ZachSweet
CC BY-SA 4.0
2021-09-08T16:50:50.100Z
You sure? I need some more info! I want to know the answer for sure
Isaac Padberg
CC BY-SA 4.0
2021-09-08T17:01:44.940Z
Alright I'm a fool. The snippet of code provided by Aoddeola pretty much sums it up.
Isaac Padberg
CC BY-SA 4.0
2021-06-22T21:49:16.950Z
2021-06-22T21:49:16.950Z
Isaac Padberg
<p>Is there a way to programmatically get all the <code>TokenName</code>s belonging to a <code>CurrencySymbol</code> with Plutus?</p>

CC BY-SA 4.0
2022-01-24T19:00:21.840Z
Do you mean all the `TokenName`s ever minted by a policy, or within a specified scope?
Mitchell Turner
CC BY-SA 4.0
2022-02-08T04:21:54.767Z
@MitchellTurner I mean all `TokenName`s ever minted by a policy. But I've come to realize that it may only be possible using an Oracle. I may be wrong tho.
Aoaddeola
<plutus>
Fetching all Tokens that belong to a Minting Policy
# Fetching all Tokens that belong to a Minting Policy

(Asked by: username_0 on 2021-06-22)

Is there a way to programmatically get all the `TokenName`s belonging to a `CurrencySymbol` with Plutus?

**Tags:** plutus
> **Comments:**
> **username_1**: Do you mean all the `TokenName`s ever minted by a policy, or within a specified scope?  
> **username_0**: @MitchellTurner I mean all `TokenName`s ever minted by a policy. But I've come to realize that it may only be possible using an Oracle. I may be wrong tho.  

---

## 2 answers

### Answer by username_2 on 2022-01-24. Score: 2

Yes. Using ghci in Plutus repo I'll show you how. I will use fully qualified functions for clarity, and don't forget to :set -XOverloadedStrings.
Plutus observes all tokens in an output using txOutValue of TxOut. To define our own Value we can do (taken from PPP Lecture#5):
> let v = Plutus.V1.Ledger.Value.singleton "a8ff" "ABC" 7 <> Plutus.V1.Ledger.Ada.lovelaceValueOf 42 <> Plutus.V1.Ledger.Value.singleton "a8ff" "XYZ" 100
> v
Value (Map [(,Map [("",42)]),(a8ff,Map [("ABC",7),("XYZ",100)])])

To filter by CurrencySymbol we can do:
> PlutusTx.AssocMap.keys $ Data.Maybe.fromJust $ PlutusTx.AssocMap.lookup "a8ff" (Plutus.V1.Ledger.Value.getValue v)
["ABC","XYZ"]

This gives you TokenNames for CurrencySymbol a8ff. Ada's CurrencySymbol of "" has been filtered out.


---

### Answer by username_3 on 2021-06-22. Score: -3

You cannot have multiple TokenNames belonging to the same CurrencySymbol. Together, TokenName & CurrencySymbol can form an asset class. Once this asset class is formed, it can be wrapped in a Value list.

The reason that TokenName & CurrencySymbol must be 1-1 is that the CurrencySymbol is the hash of the monitary policy script used to validate the Token.

If you had multiple tokens with different TokenNames using the same CurrencySymbol, they would all use the same monitary policy, and that would create some issues with validation.

> **Comments:**
> **username_4**: @Aoaddeola, you can edit and delete your own comments ;-)  
> **username_0**: Thanks @gRebel :)  
> **username_0**: According to lecture #5 of the PPP, Lars demonstrated on the command line how to combine tokens using the Value.singleton function... `singleton "a8ff" "ABC" 7 <> lovelaceValueOf 42 <> singleton "a8ff" "XYZ" 100` thereby producing: `Value (Map [(,Map [("",42)]),(a8ff,Map [("ABC",7),("XYZ",100)])])`... Hence, I fail to see how multiple TokenNames can't map to a single CurrencySymbol/Monetary Policy.  
> **username_3**: Mmmm I see the confusion. Value is simply a container for a token or multiple tokens of different types(as shown above). It is different from the CurrencySymbol. In the above example, each one of these singleton tokens have their own TokenName and  CurrencySymbol. They are then grouped using the <> operator into a Value.  
> **username_0**: Yes, you are correct in your explanation. But the fact remains that both `TokenName`s "XYZ" and "ABC" belong to the same `CurrencySymbol` "a8ff"  
> **username_3**: The same name is used by Lars because he was being slightly lazy here. When the singleton function is used on the blockchain, there will be a check to ensure that the Currency Symbol does not already exist. In the example above its okay to have the same CurrencySymbol because these functions are not being executed on the blockchain.  
> **username_0**: I'd like you to demonstrate what you mean by "there will be a check to ensure that the Currency Symbol does not already exist". You can find me on discord with same user account (aoaddeola) :)  
> **username_5**: This is an incorrect answer: there is not a 1-1 relationship between CurrencySymbol and TokenName, in fact on the contrary one can have an arbitrary number of tokens ( TokenName ) operating within the same CurrencySymbol (policy).  
> **username_3**: You sure? I need some more info! I want to know the answer for sure  
> **username_3**: Alright I'm a fool. The snippet of code provided by Aoddeola pretty much sums it up.  

---

