简体   繁体   中英

ParserError when verifying Truffle contract on Etherscan

I have a contract which has been deployed to the main Ethereum network, the contract code works and compiles fine when deploying and I can interact with the contract using metamask/MEW.

However, when I go to verify the contract on Etherscan, I get a compilation error.

I am using the beta truffle compiler from etherscan: https://etherscan.io/verifyContract2

I have bunched all of my code together using npm truffle-flattener

I have created the encoded constructor parameters using: https://abi.hashex.org/

I have then used the optimizer in truffle.js with runs = 200:

  solc: {
    optimizer: {
      enabled: true,
      runs: 200
    }
  }

I have then used the compiler version which is set in the JSON file below:

...
...
  },
  "compiler": {
    "name": "solc",
    "version": "0.4.21+commit.dfe3193c.Emscripten.clang"
  },
  "networks": {
    "1": {
      "events": {},
      "links": {
        "SaleStagesLib": "0x0ea918c7c1bed2358530baad064d361438543067",
        "BytesDeserializer": "0x278cfd9ed99cf90ebe2e1a750b50e5811a81af77"
      },
      "address": "0x3a2c34ba7be06c7104bb642f4ce74dc4c317f373",
      "transactionHash": "0x02e0a895cd3dcf98ee71b9d823d69b5701d6e76bd326757babac1c2bf805ff8d"
    }
  },
  "schemaVersion": "2.0.0",
  "updatedAt": "2018-03-31T14:09:25.579Z"
}

The following throws a ParseError in etherscan pointing towards the Ownable contract:

contract Ownable {
  address public owner;

  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() public {
    owner = msg.sender;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }


  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
    emit OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }

}

The error reads:

myc:150:30: ParserError: Expected token Semicolon got 'LParen'
    emit OwnershipTransferred(owner, newOwner)
                             ^

However, I'd like to point out that this code compiled correctly with no errors in truffle, and I have successfully interacted with the contract on the mainnet.

Any ideas why the compiler is throwing this error?

I removed the 'emits' causing the ParseError to be thrown and the verification worked. I believe this may be an issue between truffle and etherscans compiler versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM