Skip to content
Metadata

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, 6

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

Measured with JavaScript string length and TextEncoder
ExampleTextUTF-16 code unitsUTF-8 bytes
ASCIIMoss44
NFC CaféCafé45
NFD CaféCafé56
Rocket🚀24
Astronaut👩‍🚀511

Download the UTF-8 examples (CSV)

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.

Open MassLauncher

Review your saved coins and launch history in the web app.

Open web app