How Tokens are Stored Inside a UTXO
Tokens in Nexa are implemented using the Group scheme. They are only supported in P2ST addresses.
The Locking Script fields for a P2ST address are [group id, group amount, template hash, Hidden Args Hash, visible args...]. The group id and group amount fields are specifically for holding token values.
The two examples below break down two Locking Scripts, one without tokens and the other containing tokens. This should demonstrate how tokens are stored in the Locking Script.
Example output without tokens
If we look at this real transaction nexa has been sent in output 0 to address nexa:nqtsq5g53tyqxk29fptvv4uams85faqhnykzvf7lg9x60y9m.
The Locking Script for this output in the transaction is 0051148ac80359454856c6579ddc0f44f417992c2627df.
Breaking down that Locking Script into its fields yields:
00 - no group id
because there was no group id, there is no group amount.
51 - well-known template 1
14 - size of Hidden Args Hash
8ac80359454856c6579ddc0f44f417992c2627df - Hidden Args Hash
no visible args.
Example output with tokens
If we look at this real transaction some Kibble tokens have been sent from the address in input 0 to the addresses in output 0 and output 1.
The Locking Script for output 0 is 20656bfefce8a0885acba5c809c5afcfbfa62589417d84d54108e6bb42a6f300000800046bf414000000511434d247ead3bc0c0b50ddebd6b1c4fca4570755ac
It should be immediately obvious that this Locking Script is a lot longer than the one in the previous example that did not include any tokens.
Breaking down that Locking Script into its fields yields:
20 - group id size
656bfefce8a0885acba5c809c5afcfbfa62589417d84d54108e6bb42a6f30000 - group id
08 - group amount size
00046bf414000000 - group amount in little endian
51 - well-known template 1
14 - size of Hidden Args Hash
34d247ead3bc0c0b50ddebd6b1c4fca4570755ac - Hidden Args Hash
no visible args.