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

  • I just updated my code., can you please look at it – Kenny Apr 22 at 23:26
0

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.

  • It worked.. Thank you – Kenny Apr 22 at 23:45
  • Thanks for upvoting and accepting the answer. ;-) – Rob Hitchens Apr 23 at 0:46
  • 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;. – Noel Maersk Apr 23 at 9:24
  • 1
    BTW, the availability of emit was only officially announced in solidity v0.4.21. – Noel Maersk Apr 23 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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