5

Can I use an emoji in Solidity?

1 Answer 1

7

You can use an emoji directly in a string literal in Solidity versions 0.6.12 and earlier. You cannot do so with version 0.7.0 or later.

Solidity version 0.7.0 updated the parser to disallow non-printable characters in string literals. Instead, they introduced the concept of Unicode string literals, such as unicode"😃", which allows you to use emojis.

Examples

0.7.0 and higher

pragma solidity >=0.7.0;

contract MyContract {
    function myFunction() public {
        string memory myString = unicode"This is an emoji 😃";
    }   
}

0.6.12 and lower

pragma solidity <=0.6.12;

contract MyContract {
    function myFunction() public {
        string memory myString = "This is an emoji 😀";
    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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