[英]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.