Solidity

ParsedContract.sol:1:17: ParserError: Token 與 Solidity 解析器不兼容,作為 pragma 指令的一部分

  • February 14, 2019

程式碼:git clone https://github.com/dappuniversity/election https://github.com/dappuniversity/election/tree/2019_update

面臨的錯誤:

命令:

編譯:truffle compile 遷移:truffle migrate 測試合約:truffle test 執行開發伺服器:npm run dev

SANCBHAR-LW7947:選舉 sanchitbhargava $ truffle migrate Error parsing /Users/sanchitbhargava/Downloads/election/contracts/Election.sol: ParsedContract.sol:1:17: ParserError: Token incompatible with Solidity parser as part of pragma directive. pragma solidity ˆ0.4.20; ^ Compilation failed. See above. Truffle v5.0.3 (core: 5.0.3) Node v10.15.0 SANCBHAR-LW7947:election sanchitbhargava $

據我所知,Truffle v5.0.3使用solidity 編譯版本>=0.5.0。在您的契約開始時更改pragma solidity ˆ0.4.20;pragma solidity ˆ0.5.0;可能會解決您的問題。

另一方面,這可能會產生其他問題。因為syntaxsolidity ˆ0.4.20有點solidity ˆ0.5.0不同。主要是你怎麼寫constructor例子:

solidity ˆ0.4.20

   function <name same as contract>() public {}

solidity ˆ0.5.0

   constructor() public {}

引用自:https://ethereum.stackexchange.com/questions/67071