What is the maximum size of text held in the memo portion of a lightning network payment request?
1 Answer
The memo field can hold 639 bytes of information.
But how many characters? Let's assume utf8 (since lncli encodes the text in utf8)
utf8's characters are variable length, meaning some are larger than others.
From stackoverflow:
The first 128 characters (US-ASCII) need one byte.
The next 1,920 characters need two bytes to encode. This covers the remainder of almost all Latin alphabets, and also Greek, Cyrillic, Coptic, Armenian, Hebrew, Arabic, Syriac and Tāna alphabets, as well as Combining Diacritical Marks.
Three bytes are needed for characters in the rest of the Basic Multilingual Plane, which contains virtually all characters in common use[12] including most Chinese, Japanese and Korean [CJK] characters.
Four bytes are needed for characters in the other planes of Unicode, which include less common CJK characters, various historic scripts, mathematical symbols, and emoji (pictographic symbols).
For the US-ASCII character set and onward:
639 bytes / (1 byte / 1 char) = 639 characters
639 bytes / (2 byte / 1 char) = 319 characters
639 bytes / (3 byte / 1 char) = 213 characters
639 bytes / (4 byte / 1 char) = 159 characters