Jørgen S. Notland

Nexa tokens explained: groups, authorities and the token description document


This is a developer tutorial on Nexa's native tokens ("groups"). I checked the claims against the spec pages and source code listed below. Where the spec is silent or out of date, I cite the nexa full node source (NODE: src/ on gitlab.com/nexa/nexa) instead. Claims I could not confirm against a primary source were removed.

Sources

File:line references such as token.kt:249-253 point into those directories at those commits. The main libnexakotlin files are token.kt, wallet.kt, iWallet.kt, script.kt, primitives.kt and blockchainFactory.kt; the test referenced is groupTokenTests.kt.


1. What is a Nexa token?

Nexa has native, consensus-level tokens called Group Tokenization. Miners validate token amounts the same way they validate NEX. Tokens do not depend on a smart contract or on a layer-2 data-carrier protocol (SPEC-GROUP, "Introduction").

Comparison with other token systems

Nexa groupsColored coins (OP_RETURN protocols, e.g. SLP)
Validated by minersYes (SPEC-GROUP)No (indexers/wallets)
Where the amount livesUTXO script template fieldOff-chain interpretation of OP_RETURN
Issuance controlAuthority UTXOs (MINT/MELT/…)Protocol-specific
MetadataGenesis OP_RETURN + signed off-chain TDDProtocol-specific

2. What a token is made of, field by field

2.1 Group ID

2.2 Quantity

2.3 Subgroups

2.4 Authority outputs and flags

Authority flags are stored in the 64-bit amount field (LNK primitives.kt:332-345):

FlagBit valueMeaning
AUTHORITY0x8000000000000000Marks this output as an authority, not a token amount
MINT0x4000000000000000Can create tokens
MELT0x2000000000000000Can destroy tokens
BATON0x1000000000000000Can create new authority outputs (pass on or copy authority)
RESCRIPT0x0800000000000000Can move tokens/authorities to a different script (relevant for covenanted groups)
SUBGROUP0x0400000000000000Can create subgroups
ALL_AUTHORITIESOR of all the above

The lower bits of the authority amount hold the genesis nonce (wallet.kt:7089). GroupInfo.isAuthority() is at primitives.kt:376. spec.nexa.org has no normative page listing these bits; they are defined in the node (GroupAuthorityFlags in NODE grouptokens.h: AUTHORITY = 1<<63 … SUBGROUP = 1<<58) and enforced in CheckGroupTokens (NODE grouptokens.cpp):

The NiftyArt genesis authority amount is 0xfc… (all six flags) plus the nonce, which matches these values.

2.5 Token genesis info (on-chain)

This is an OP_RETURN output in the genesis transaction (SPEC-TDD "Token Genesis Information"). Each field is a separate push. OP_FALSE means the field is empty.

OP_RETURN 88888888 <ticker> <name> <uri> <32-byte doc hash> [decimal_places]

2.6 Token Description Document (off-chain)

This is a signed JSON file hosted at <uri>. The genesis commits to it with a SHA-256 hash. Details are in §3.


3. The Token Description Document (TDD) in detail

3.1 Exact format (SPEC-TDD)

The file is an I-JSON array with two elements: a dictionary, then a base64 signature string.

[{
  "ticker": "string, required",
  "name": "string, optional",
  "summary": "string, optional",
  "description": "string, optional",
  "legal": "string, optional",
  "creator": "string, optional",
  "contact": { "method": "string, optional", "method2": "string, optional" },
  "icon": "string, optional, URI.",
  "category":"string, optional"
 },
"<signature>"]

libnexakotlin parses the file into TokenDesc (token.kt:76-101). It parses with ignoreUnknownKeys = true (token.kt:231-233), so it keeps only ticker, name, summary, description, legal, creator, category, contact, icon plus the NFT extensions nftId and nftUrl (token.kt:87-89). nftId/nftUrl are libnexakotlin extensions. I did not find them on the SPEC-TDD page.

3.2 What is hashed, and how

3.3 Signature

3.4 How a wallet fetches and verifies the TDD (libnexakotlin getTokenInfo, token.kt:303-440)

  1. Ask a P2P full node for token info (get1TokenInfo). If none supports it, ask Rostrum: getTokenGenesisInfo (token.kt:338-401).
  2. Fetch the URI with Url(uri).readText(5000 ms timeout) (token.kt:361, token.kt:414).
  3. Parse the document, recover the pubkey, and check that the signer is the genesis authority's address. If so, set tddAddr (token.kt:374-375, 418).
  4. Hash check is done by Wally, not by getTokenInfo: WALLY assets.kt:1019-1020 caches the TDD only if tg.document_hash == td.tddHash.toHex(). If it doesn't match, the TDD is still returned but not cached as good (assets.kt:1026-1029). Wally does not reject the document, so check your own UI logic.

3.5 Can the URL be IPFS?


4. "Is it like a JSON object I can put any data string I want into?"

Short answer: partly. The on-chain token is not a free-form JSON object. It is a fixed binary structure: a group ID, an amount, and template fields. Free-form data can go in a few specific places:

PlaceFree-form?Limits / rules
Group ID (32 bytes)No. It is a hash of outpoint + OP_RETURN + authority amount (flags + nonce); the last two bytes are flag bitsExactly 32 bytes for the parent group
AmountNo. It is a number or authority flags2/4/8 bytes
Subgroup bytesYes, arbitrary bytesUp to 488 bytes in libnexakotlin (520 − 32); no explicit node maximum. For spec-conforming NFTs these bytes MUST be the double SHA-256 of the NFT zip (SPEC-NFT)
Genesis OP_RETURNFixed field order and meaning. The values are free UTF-8 textTicker, name and URI strings, a 32-byte hash, decimals. Standard relay limit 223 bytes of OP_RETURN data (NODE policy/policy.h). The data is also immutable
NFT OP_RETURN 88888889Fixed fields: title, hash, URL, optional public-zip hashSame as above
TDD JSON dictionaryYes. Defined fields, plus any additional fields you addHash-committed and signed, so it is immutable once genesis is mined. Stays off-chain. Wally/libnexakotlin ignore unknown keys
NFT zip info.jsonYes. data: {…} is explicitly "application-specific", and bindata is hexZip ≤ 50 MB recommended. cardf/cardb ≤ 2 MB each. Never re-zip the file

So the off-chain TDD and the NFT info.json are the "JSON objects you can put anything in". The chain commits only to their hash.


5. Authorities and lifecycle walkthrough

Walkthrough with nexa-cli (SPEC-GROUP RPCs)

  1. Create the token: token new [address] NIFTY NiftyArt https://…/nifty.json <sha256>. It returns the groupIdentifier, the tx and tokenDescriptorSigningAddress.
  2. Sign the TDD: signmessage <signingAddr> "$(cat nifty.json)". Then wrap it as [dict, "sig"] and host it.
  3. Mint: token mint <group> <addr> 100000
  4. Transfer: token send <group> <addr> 42
  5. Melt: token melt <group> <addr> 100 (SPEC-GROUP syntax; the current node help lists token melt <groupId> <quantity>, NODE wallet/grouptokenwallet.cpp)
  6. Renew or delegate authority: build a tx that spends a BATON authority and outputs new authority outputs. The node wallet has token authority create <groupId> <address> [mint melt nochild rescript], plus token authority list/count/destroy (NODE wallet/grouptokenwallet.cpp, token help text); these are not on spec.nexa.org.
  7. Create an NFT: spend a SUBGROUP authority and output to parent+hash256(zip) with quantity 1 (see the Kotlin code below).

6. NFTs on Nexa


7. Kotlin examples (libnexakotlin)

These APIs exist in the code at the cited lines. Wallet setup is omitted.

// 1. Build genesis OP_RETURN with a TDD commitment            (script.kt:2466-2480, primitives.kt:28-31)
// Use makeTokenDesc with a Hash256: Hash256(hex) reverses the bytes, which gives the on-chain
// order nexad uses (NiftyArt pushes 0b4a… for sha256sum b0fa…). GroupDescriptor.buildGenesisData()
// pushes the raw sha256 bytes (the opposite order), so don't use it for the genesis OP_RETURN.
val tddDict = """{"ticker":"DEMO","name":"Demo Token","summary":"test"}"""  // exact bytes!
val tddSha256Hex = libnexa.sha256(tddDict.toByteArray(Charsets.UTF_8)).toHex()  // = sha256sum output
val opRet: SatoshiScript = SatoshiScript.makeTokenDesc(ChainSelector.NEXA, "DEMO", "Demo Token",
    "https://example.com/demo.json", Hash256(tddSha256Hex), 2)
val gd = GroupDescriptor(ticker = "DEMO", name = "Demo Token",
                         docUri = "https://example.com/demo.json", doc = tddDict, decimals = 2)  // used in step 3

// 2. Create the group; returns unsent tx + GroupId           (iWallet.kt:699, wallet.kt:7083-7093)
val authAddr = wallet.getnewaddress()
val (genesisTx, gid) = wallet.newToken(authAddr, opRet, GroupIdFlags.NONE.v)  // default ALL_AUTHORITIES
wallet.send(genesisTx)

// 3. Signed TDD to host at docUri, signed by the genesis address  (token.kt:479-491)
val tddFile: String? = gd.buildTokenDescriptionDoc(wallet, authAddr)

// 4. Mint                                                    (iWallet.kt:712, wallet.kt:7096-7101)
wallet.send(wallet.mintTokens(wallet.getnewaddress(), gid, 1_000_000L))

// 5. Transfer tokens                                         (iWallet.kt:551-557)
wallet.send(42L, PayAddress("nexa:..."), gid)

// 6. NFT as a subgroup                                       (primitives.kt:263, iWallet.kt:1156)
val zip: ByteArray = /* your .nft zip bytes */ byteArrayOf()
val nftGid = gid.subgroup(libnexa.hash256(zip))
wallet.send(wallet.createSubgroup(wallet.getnewaddress(), nftGid, 1UL, null))

// 7. Inspect an output                                       (script.kt:2192, primitives.kt:350, 376)
val gi = someOutput.script.groupInfo(someOutput.amount)
if (gi?.isAuthority() == true) println(GroupAuthorityFlags.toString(gi.authorityFlags))

// 8. Fetch + verify a TDD                                    (token.kt:303)
val td = getTokenInfo(gid, { /* ElectrumClient */ TODO() }, null)
val ok = td.tddHash?.toHex() == td.genesisInfo?.document_hash && td.tddAddr != null
// PSEUDOCODE (no dedicated melt / authority-renew helper found in libnexakotlin)
// melt: tx inputs = tokens + MELT authority; outputs = fewer tokens (+ authority back if BATON)
// renew: input = authority with BATON; outputs = N new authority outputs with chosen flag subsets
// burn mint: spend every MINT authority to ungrouped outputs only

wallet.send(tx) is in iWallet.kt:654. Note that wallet.getnewaddress() is used in groupTokenTests.kt:206.


8. Pitfalls and security notes

  1. The TDD hash breaks on whitespace. A trailing newline, editor reformatting, or re-encoding the JSON will all break it. libnexakotlin slices from the first { to the last }.
  2. Genesis data is permanent. The ticker, name, URI, hash and decimals are part of the group ID preimage. If they are wrong, you must create a new group (SPEC-TDD).
  3. Lock the genesis authority to a P2PKT/P2PKH address, otherwise TDD signature verification is impossible. Sign the genesis tx with SIGHASH ALL.
  4. Wally does not hard-fail on a hash mismatch. It only skips caching (WALLY assets.kt:1020-1029). Show unverified metadata as untrusted in your UI.
  5. Use http(s) only; ipfs:// is not fetched. Use https rather than http, to prevent man-in-the-middle attacks on the domain binding.
  6. The icon URL is not committed. It can change at any time, so never use it as NFT content.
  7. Wallets should not show reserved tickers (NEX, ISO-4217 currency codes, stock tickers); SPEC-TDD recommends showing ??? instead.
  8. BATON copies authority. For a provably fixed supply, audit every authority UTXO.
  9. HOLDS_NEX groups need a 0 token quantity. COVENANT groups need the same script template on output as on input (RESCRIPT is needed to change it).
  10. Never re-zip an NFT. Its hash is its identity.
  11. Each token output needs dust NEX. Fees are paid in NEX.

Open points