我有一份合同已经部署到主要的以太坊网络,合同代码在部署时可以正常编译,我可以使用metamask / MEW与合同进行交互。
但是,当我去验证Etherscan上的合同时,我收到了编译错误。
我正在使用etherscan的beta truffle编译器:https://etherscan.io/verifyContract2
我使用npm truffle-flattener
将所有代码拼凑在一起 创建了编码的构造函数参数然后我在truffle.js中使用了运行= 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"
}
以下内容抛出了指向Ownable合同的etherscan中的ParseError:
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)
^
但是,我想指出这段代码编译正确,松露没有错误,我已经成功地与主网上的合同进行了互动。
为什么编译器会抛出此错误?
答案 0 :(得分:0)
我删除了'发出'导致ParseError被抛出并且验证工作。我相信这可能是松露和etherscans编译器版本之间的问题。