1

I got this particular Parser error and can you help me how to fix this issue:while using this code

pragma solidity ^0.4.17;

import "../node_modules/zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";

contract MyToken is StandardToken {
string public name = "MyTok";
string public symbol = "MTK";
uint8 public decimals = 2;
uint public INITIAL_SUPPLY = 5000;

function MyToken () public {
    totalSupply__ = INITIAL_SUPPLY;
    balances[msg.sender]= INITIAL_SUPPLY;
    emit Transfer(0x0,msg.sender,totalSupply_);

    }
}

In the line emit Transfer(0x0,msg.sender,totalSupply_);

localhost/mytoken/contracts/mytoken.sol:14:18: ParserError: Expected token Semicolon got 'LParen' Thanks

1
  • I just updated my code., can you please look at it Apr 22, 2019 at 23:26

1 Answer 1

1

I got this to compile with solidity 0.4.18;

pragma solidity ^0.4.17;

import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-solidity/v1.6.0/contracts/token/ERC20/StandardToken.sol";

contract MyToken is StandardToken {
    string public name = "MyTok";
    string public symbol = "MTK";
    uint8 public decimals = 2;
    uint public INITIAL_SUPPLY = 5000;

    event Transfer(address s, address s2, uint amount);

    function MyToken () public {
        totalSupply_ = INITIAL_SUPPLY;
        balances[msg.sender] = INITIAL_SUPPLY;
        Transfer(0x0,msg.sender,totalSupply_); // solc 0.4.18 does not have `emit`
    }
}

The emit keyword is unexpected by your compiler. The error is a little misleading. Just drop the word emit.

It can be a bad idea to mix up the compiler versions. A higher order concern would be to catch up to a more recent build of Open Zeppelin and a recent compiler. For example:

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/ERC20.sol

Hope it helps.

2
  • 1
    Your answer shows well how the commonly-used caret-pragma produces unexpected results when the underlying compiler isn't yet at v1. Perhaps you should remove the caret and pin solc's version, like pragma solidity 0.4.17;. Apr 23, 2019 at 9:24
  • 2
    BTW, the availability of emit was only officially announced in solidity v0.4.21. Apr 23, 2019 at 9:28

Your Answer

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

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