library / How to use Solana / HS0050
Token group membership check
One TypeScript file takes Token-2022 mints, or finds recent ones, and checks each against its group: the member record, the pointer, and the group's own record. It only reads, with no keypair and no signature.
Membership is two records agreeing
A mint's name and image are whatever its issuer typed and hosted. Anyone can copy them onto another mint. The evidence that holds up is on chain: Token-2022 can record that a mint belongs to a group, and the program writes that record only when the group's update authority signs for it, together with the member mint's own authority.
That leaves a check with two halves that have to agree. The member mint carries a record that names a group address. The account at that address carries a group record of its own, with the same address inside it. A mint that names a group the group never wrote, or an account that is no group at all, fails one half and is not a member.
The four extensions
Token-2022 keeps group data in four mint extensions, numbered 20 to 23. Each sits in the area after the mint's base data: 82 bytes of mint, zero padding up to byte 165, one account type byte at 165 (1 for a mint), then entries from byte 166. An entry is a little-endian u16 type, a little-endian u16 length, and the value.
| Type | Extension | Value bytes | Layout |
|---|---|---|---|
| 20 | Group pointer | 64 | authority (32), group address (32) |
| 21 | Group | 80 | update authority (32), mint (32), size (u64), max size (u64) |
| 22 | Group member pointer | 64 | authority (32), member address (32) |
| 23 | Group member | 72 | mint (32), group (32), member number (u64) |
The pointers say where a record lives. Token-2022 writes group and member records only inside the mint itself, so an ordinary group mint has a group pointer naming that mint, and an ordinary member mint has a member pointer naming that mint. A pointer aimed at another account means another program keeps the record, and the Token-2022 owner check cannot vouch for it. The file stops at that case and prints the address.
The checks in order
- The account at the mint address exists and its owner is the Token-2022 program, TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb. A classic Token mint has no extensions, so it cannot be a member.
- Byte 165 is 1 and the entry walk collects the entries. If type 22 is present, its member address is the mint itself or the all-zero address. Any other address is a pointer aimed elsewhere, and the walk stops there.
- The entries include type 23. With no type 23 the mint is not a member.
- The group address is bytes 32 to 63 of the type 23 value.
- The account at that group address exists, is owned by Token-2022, carries type 21, and the mint field inside that entry (bytes 32 to 63) equals the address just read.
- When all five pass, the mint is a member. The member number is the last 8 bytes of the member entry and the group's current size is at bytes 64 to 71 of the group entry.
The owner checks in steps 1 and 5 carry the trust. Any program can own an account whose bytes look like these layouts, and only Token-2022 enforces who may write them. Its member instruction needs a signature from the group's update authority, and it raises the group's size in the same step. A record in a Token-2022 account therefore means the group's authority approved that mint, and the same bytes in an account owned by something else mean nothing.
The code
Add @solana/kit 8.6.0 to the project, set CARBIUM_KEY and start the file on Node 24, which strips the types on load. Pass mints as arguments to check them. With none, the file takes the newest ten signatures of the Token-2022 program, reads each transaction and collects the mints in its postTokenBalances.
// HS0050 · Token group membership check// https://carbium.sh/library/howsolana/token-group-membership-check// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";const ZERO = "11111111111111111111111111111111";const NAMES: Record<number, string> = { 18: "metadataPointer", 19: "tokenMetadata", 20: "groupPointer", 21: "tokenGroup", 22: "groupMemberPointer", 23: "tokenGroupMember" };const decoder = getAddressDecoder();const addr = (b: Buffer, at: number) => decoder.decode(b.subarray(at, at + 32));async function fetchAll(list: string[]) { const res = await rpc.getMultipleAccounts(list.map((a) => address(a)), { encoding: "base64" }).send(); return res.value.map((v) => v && { owner: String(v.owner), data: Buffer.from(v.data[0], "base64") });}function walk(d: Buffer) { // type-length-value entries start at byte 166 const out = new Map<number, Buffer>(); if (d.length <= 166 || d[165] !== 1) return out; for (let o = 166; o + 4 <= d.length; ) { const type = d.readUInt16LE(o), len = d.readUInt16LE(o + 2); if (type === 0) break; out.set(type, Buffer.from(d.subarray(o + 4, o + 4 + len))); o += 4 + len; } return out;}async function newestMints() { const sigs = await rpc.getSignaturesForAddress(address(TOKEN_2022), { limit: 10 }).send() .catch((e: Error) => { console.error(`getSignaturesForAddress failed: ${e.message}`); return []; }); const mints = new Set<string>(); for (const s of sigs) { if (s.err) continue; try { const tx = await rpc.getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed" }).send(); for (const b of tx?.meta?.postTokenBalances ?? []) mints.add(b.mint); } catch (e) { console.error(`getTransaction failed: ${(e as Error).message}`); } } return [...mints];}const mints = (process.argv.length > 2 ? process.argv.slice(2) : await newestMints()).slice(0, 100);if (!mints.length) { console.error("No mints to check."); process.exit(1); }const accts = await fetchAll(mints).catch((e: Error) => { console.error(`mint read failed: ${e.message}`); return process.exit(1); });const rows = mints.map((m, i) => { const a = accts[i]; if (!a) return { m, say: "no account" }; if (a.owner !== TOKEN_2022) return { m, say: "not a Token-2022 mint" }; const ext = walk(a.data); const list = [...ext.keys()].map((t) => NAMES[t] ?? `type ${t}`).join(", ") || "no extensions"; const ptr = ext.get(22), mem = ext.get(23); const at = ptr ? addr(ptr, 32) : m; if (at !== m && at !== ZERO) return { m, list, say: `pointer elsewhere, member data at ${at}` }; if (!mem) return { m, list, say: "not a member" }; return { m, list, say: "", group: addr(mem, 32), num: mem.readBigUInt64LE(64) };});const groups = [...new Set(rows.flatMap((r) => (r.group ? [r.group] : [])))];const records = new Map<string, Buffer | null>(); // group entry bytes, or null when the account is no grouptry { const got = groups.length ? await fetchAll(groups) : []; got.forEach((a, i) => { const rec = a && a.owner === TOKEN_2022 ? walk(a.data).get(21) : undefined; records.set(groups[i], rec && addr(rec, 32) === groups[i] ? rec : null); });} catch (e) { console.error(`group read failed: ${(e as Error).message}`); }for (const r of rows) { let say = r.say; if (r.group) { const g = records.get(r.group); say = g ? `member #${r.num} of group ${r.group} (size ${g.readBigUInt64LE(64)})` : g === null ? `claims group ${r.group}, but that account holds no group record` : `claims group ${r.group}, but the group account could not be read`; } console.log(`${r.m}: ${r.list ? `[${r.list}] ` : ""}${say}`);}
run: node main.ts [mint-address ...]
One getMultipleAccounts call reads every mint, at most 100 of them, in base64. The file decodes the entries itself, so the check is the layout in the table and nothing a node's parser might add. A second call reads the distinct group addresses the first pass named. The transaction reads pass maxSupportedTransactionVersion: 1, which mainnet needs because it carries v1 transactions. A failed transaction read or group read is printed and the run goes on. A failed signature list or a failed first mint read is printed and ends the run.
Reading the output
Each mint gets one line: the address, the extensions found by number or name, and a verdict.
| Verdict | Meaning |
|---|---|
| no account | Nothing exists at the address on this read. |
| not a Token-2022 mint | The owner is another program, so no group records can be trusted there. |
| not a member | The mint has no member record. |
| pointer elsewhere, member data at X | The member pointer names account X, so the member record is not in the mint. |
| member #n of group G (size s) | Both halves agree. The group's authority approved the mint. |
| claims group G, but that account holds no group record | The member record names an account that is no group. |
| claims group G, but the group account could not be read | The second read failed. Run it again. |
With no argument the newest mints are mostly ordinary tokens, so expect a column of not a member. That output still shows the check working, because each of those mints was read and its entries were walked. To see a member, pass a mint you suspect and read the group address it prints against the one the issuer announced.
On Carbium
Every read goes to https://services.carbium.sh unless CARBIUM_RPC_URL says otherwise. `getMultipleAccounts` costs 10 cells per pubkey: 1000 cells for 100 pubkeys, 1001 over a 4 KiB body. It takes up to 300 pubkeys, but the 1,024-cell burst caps a call at 100 below Pro, so the file sends 100 at most. A Pro account can raise that cap.
Discovery is the dearer part. getSignaturesForAddress costs 50 cells and each getTransaction costs 50, so ten transactions come to 550 cells before the account reads start. The calls leave out a commitment, and kit fills in confirmed. The transaction reads name confirmed themselves.
getSignaturesForAddress pages come from an address index that reaches back 30 days at most, and it can list a signature that getTransaction answers with null. The file skips a null. Because it reads the newest signatures, this seldom matters.
Where it ends
The check proves that a mint belongs to the group at one address. It cannot tell you that this group is the one you care about. Take the group address from the issuer's own announcement or from a mint you already trust, and compare it with the line the file prints.
It cannot list a group's members. Finding them all means a program-wide account scan, and Carbium answers getProgramAccountsV2 with -32601. The size in the output tells you how many members the group has recorded, which you can compare with the list you are checking.
A member record says nothing about a mint's name, image or metadata. For those, use the Token-2022 metadata lookup. The answer is also as of a confirmed read, so a mint whose creating transaction has not reached confirmed yet comes back as no account.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| A mint you expected in a group prints not a member. | The group claim may rest on something else, such as a name or a metadata field, and this file reads none of those. Only a type 23 entry in a Token-2022 mint counts. |
| The line says pointer elsewhere. | Read the account the line prints with getAccountInfo and judge it by its owner program. |
| The line says claims group G, but that account holds no group record. | Treat the mint as not a member, and ask the issuer which address is the real group. |
| getTransaction answers null or an error during discovery. | A signature from the address index can sit below the validator's ledger floor, so the file skips a null and prints other failures. With the version left out, -32015 comes back for a v1 transaction, so keep the version setting. |
| The run stops with No mints to check. | The newest transactions held no token balances, or the signature list failed and printed its error. Run it again, or pass a mint address as the first argument. |
Questions
Is the group address the same as the group mint?
Yes, because Token-2022 requires it: the group record is written only inside a mint, so a group address is always a group mint. The file still reads whatever account the member names and requires a group record whose mint field equals that address.
Why decode the bytes by hand?
The check then rests on the extension layout and nothing else. Four short entries decode in a few lines, and the same code works on any node that serves getMultipleAccounts in base64.
Can a mint be in more than one group?
A mint carries one member entry, so it names one group. A mint can still be a group itself, with a type 21 entry of its own, and the file lists both extensions by name, tokenGroup and tokenGroupMember.
Do I need a private key for this?
No. The file only reads accounts and transactions. The Carbium key identifies your account to the RPC.