Can I use an emoji in Solidity?
1 Answer
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 😀";
}
}