6

Is there a way to programmatically get all the TokenNames belonging to a CurrencySymbol with Plutus?

2
  • Do you mean all the TokenNames ever minted by a policy, or within a specified scope? Jan 24, 2022 at 19:00
  • @MitchellTurner I mean all TokenNames 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
    Feb 8, 2022 at 4:21

2 Answers 2

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.

-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.

10
  • 1
    @Aoaddeola, you can edit and delete your own comments ;-)
    – gRebel
    Jun 23, 2021 at 9:53
  • Thanks @gRebel :)
    – Aoaddeola
    Jun 23, 2021 at 12:33
  • 2
    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
    Jun 23, 2021 at 12:33
  • 1
    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. Jun 24, 2021 at 12:50
  • 1
    Yes, you are correct in your explanation. But the fact remains that both TokenNames "XYZ" and "ABC" belong to the same CurrencySymbol "a8ff"
    – Aoaddeola
    Jul 1, 2021 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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