How to count UTF-8 bytes in a Solana token name
By MassLauncher · Updated · 4 min read
Café can take five or six bytes in UTF-8, depending on how the accent is encoded. Count the exact string you will submit before relying on a character counter.
Measure the text you will send
TextEncoder encodes a JavaScript string as UTF-8. Its output length counts bytes. JavaScript’s string length counts UTF-16 code units. Neither number necessarily matches the number of characters a person sees: the astronaut below is a single displayed emoji made from multiple code points.
const text = "Cafe\u0301";
const bytes = new TextEncoder().encode(text).length;
console.log(text.length, bytes); // 5, 6Five strings with different byte counts
With 27 ASCII letters before Café, the NFC spelling is 32 bytes and the NFD spelling is 33. Try text.normalize("NFC") if you intend to submit the normalized spelling. Then measure and submit that same value; normalizing a test copy does not change the original input.
| Example | Text | UTF-16 code units | UTF-8 bytes |
|---|---|---|---|
| ASCII | Moss | 4 | 4 |
| NFC Café | Café | 4 | 5 |
| NFD Café | Café | 5 | 6 |
| Rocket | 🚀 | 2 | 4 |
| Astronaut | 👩🚀 | 5 | 11 |
Check which limit applies
The Metaplex Token Metadata program caps the name at 32 UTF-8 bytes and the symbol at 10. Those are limits of that metadata program. Pump.fun documents limits for its own create_v2 instruction, which uses Token-2022, so read that instruction separately instead of copying the Metaplex limits into every validator.
The MassLauncher web coin form shows a 32-unit name counter based on JavaScript string length. Its counter measures the form input, which can fit even when the UTF-8 encoding is longer than 32 bytes. For example, 28 ASCII letters followed by NFC Café use 32 UTF-16 units and 33 UTF-8 bytes.