繁体   English   中英

在Etherscan上验证松露合约时发生ParserError

[英]ParserError when verifying Truffle contract on Etherscan

我有一个已部署到以太坊主网络的合约,该合约代码在部署时可以正常工作并编译良好,并且可以使用metamask / MEW与该合约进行交互。

但是,当我在Etherscan上验证合同时,出现编译错误。

我正在使用etherscan的beta松露编译器: https ://etherscan.io/verifyContract2

我已经使用npm truffle-flattener将所有代码打包在一起

我使用以下方法创建了编码的构造函数参数: https : //abi.hashex.org/

然后,我在truffle.js中使用runs = 200的优化程序:

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

然后,我使用了在以下JSON文件中设置的编译器版本:

...
...
  },
  "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"
}

下面的代码在etherscan中抛出一个ParseError,指向Ownable合约:

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;
  }

}

该错误显示为:

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

但是,我想指出的是,此代码已正确编译,没有松露错误,并且我已经成功地与主网上的合同进行了交互。

有什么想法为什么编译器会抛出此错误?

我删除了导致引发ParseError的“事件”,并且验证工作正常。 我认为这可能是松露和etherscans编译器版本之间的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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