1

In a smart contract where the token name and symbol are defined, is unicode supported or should these be ASCII only characters?

As below, would it be a valid contract or token symbol?

    constructor() public
    ERC721("✕ray Ýour ℤen", "✕Ýℤ")  
    {
        _setBaseURI("https://foo.foo");
    }
3

As mentioned by Linum Labs, that approach can be used for solidity v 0.7 and higher. If you want to use an older version,

From docs:

\uNNNN (Unicode escape)

You will need to convert Unicode character to escape sequence, For example:

✕ray Ýour ℤen

will be

\u2715ray \u00ddour \u2124en

And Important NOTE from docs:

Any unicode line terminator which is not a newline (i.e. LF, VF, FF, CR, NEL, LS, PS) is considered to terminate the string literal. Newline only terminates the string literal if it is not preceded by a .

3

Welcome!

Just as a quick note, you mention "smart contracts" in the question, but give code that looks like Solidity, and also have a Solidity tag in your question, so I assume that the question's focus is Solidity. Different languages may handle Unicode differently, so the answer can change from language to language.

Solidity (v0.7 and higher)

(see hack3r_0m's answer for older versions of Solidity)

From the docs:

While regular string literals can only contain ASCII, Unicode literals – prefixed with the keyword unicode – can contain any valid UTF-8 sequence. They also support the very same escape sequences as regular string literals.

string memory a = unicode"Hello 😃";

This means the code as provided in the question would not work (regular strings are ASCII-encoded), but that by prefacing the string with unicode, it should work.

Vyper

In Python 3.x the built-in string type uses utf-8 encoding. As such, our assumption is that Unicode characters should be natively supported in strings. Remix seems to be down for us at the moment, so we don't have a simple way to test this at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.