0

I need to write a contract that uses verbiage from a latin based language. Which takes special characters such as é, ç, ã, ô etc....

I'm using Hard hat to write it.

I've found an example here, also using open Zeppelin:

Example that works

enter image description here

When trying to write something similar in my contract I get an error: Invalid character in string.

    contract Ouro is ERC20, Ownable {

    string public constant tokenMinuta = "Céu, Carraço"; // "Céu, Carraço" is the Problem to solve here

    constructor() ERC20("Ouro", "ORO") {
        _mint(msg.sender, 1000000000 * 10**decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }

}

I then added UTF-8-encoded to those caracters with hopes that would compile correctly on either BSCScan or EtherScan:

i.e. string public constant tokenMinuta = "C\xC3\xA9u, Carra\xC3\xA7o";

The above compiles as it should in my terminal see here: enter image description here

However it does not work when I add the source code to BSCScan or EtherScan.

Special Character not compiled on a human readable way

See where I added the UTF-8 - My hope is that this would compile on a human readable way and not like these:

enter image description here

My question is: How can I write those special characters in the body of contract without getting compiling errors and therefore be able to verify that contract with those characters on a humanly readable ways on either BSCSan or EtherScan? To work just like the very first example I've provided above.

Null isTrue
  • 1,882
  • 6
  • 26
  • 46

1 Answers1

1

What's the solc compiler version you're using? I am compiling with 0.5.16 and it works with UTF-8 letters in the source code.

Don't UTF-8-encoded these letters in the string, it won't be transpiled yet.

Yijia Su
  • 314
  • 1
  • 5
  • I'm using HardHat and `pragma solidity ^0.8.0;` I don't understand your second part, I should not use the UTF-8 on a string? That's where I need to solve the problem. I need those special characters – Null isTrue May 02 '21 at 17:18