Skip to content

Solidity: If a dev passes a unicode string as token name, unicode"..." string literal should be used #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
0xNeshi opened this issue Mar 5, 2025 · 1 comment · May be fixed by #476
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@0xNeshi
Copy link
Contributor

0xNeshi commented Mar 5, 2025

Currently passing Unicode strings as token names is supported in Wizard, but it produces invalid Solidity code.

For example, if we open Wizard Solidity and in the "Name" field we type MyTokeć, this will be the output:

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract MyTokec is ERC20, ERC20Permit {
    constructor() ERC20("MyTokeć", "MTK") ERC20Permit("MyTokeć") {}
}

But this is not valid Solidity code as string literals must be ASCII characters, so the compiler will throw an error. To make this compile, the string literal must be prepended with the unicode keyword:

contract MyTokec is ERC20, ERC20Permit {
    constructor() ERC20(unicode"MyTokeć", "MTK") ERC20Permit(unicode"MyTokeć") {}
}
@0xNeshi 0xNeshi added the bug Something isn't working label Mar 5, 2025
@ericglau ericglau added the good first issue Good for newcomers label Mar 5, 2025
MKVEERENDRA added a commit to MKVEERENDRA/contracts-wizard that referenced this issue Mar 5, 2025
Fix: Use unicode string literal for token names with non-ASCII characters (OpenZeppelin#475)

- Token names with accents/symbols (e.g., "MyTokeć") now use Solidity’s `unicode"..."` syntax  
  to prevent compilation errors.
- Double quotes in names/symbols are escaped (`\"`) to avoid syntax issues.
- Developers can now use any Unicode name without manual code adjustments.

Fixes OpenZeppelin#475
@MKVEERENDRA
Copy link

I’ve submitted a fix that automatically prepends the unicode keyword for token names that containing non-ASCII characters (and escapes any double quotes), ensuring that the generated Solidity code compiles correctly. You can check out the changes in my PR #476.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
3 participants