2

Take the following code:

pragma solidity 0.4.24;

contract TestCoin {
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    constructor(uint256 initialSupply) public {
        totalSupply = initialSupply;
        balanceOf[msg.sender] = totalSupply;
    }
}

This code works fine locally and works fine in Remix. But when trying to deploy this contract from the Ethereum wallet I get the following error:

     Could not compile source code. 
Expected identifier, got 'eth_compileSolidity'
    constructor(uint256 initialSupply) public {
               ^

This question was already asked here, Expected identifier, got 'eth_compileSolidity' constructor () public {. The question was never actually answered but the person who asked the question apparently fixed it.

1

1 Answer 1

1

I have figured out the answer.

The Ethereum wallet comes bundled with a Solidity compiler. I'm using version 0.10.0 of the Ethereum wallet. The bundled compiler seems to come with support for version 0.4.21 of Solidity.

However the use of the constructor() keyword was not introduced until version 0.4.22.

So if you're experiencing the same issue as me, change your code to resemble:

pragma solidity 0.4.21;

contract TestCoin {
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    function TestCoin(uint256 initialSupply) public {
    totalSupply = initialSupply;
    balanceOf[msg.sender] = totalSupply;
  }
}
1
  • A nice answer. Don't forget to mark it as answered, using the green tick, in order to remove the question from the unanswered list. You may have to wait a day or so to be able to do that though. Jul 5, 2018 at 12:09

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.